store: Add 'references/cached'.
authorLudovic Courtès <ludo@gnu.org>
Sun, 29 Mar 2020 00:21:32 +0000 (01:21 +0100)
committerLudovic Courtès <ludo@gnu.org>
Sun, 29 Mar 2020 13:32:17 +0000 (15:32 +0200)
* guix/store.scm (references/cached): New procedure.

guix/store.scm

index b3641ef..ca8c0e5 100644 (file)
 
             built-in-builders
             references
+            references/cached
             references/substitutes
             references*
             query-path-info*
@@ -1393,6 +1394,13 @@ error if there is no such root."
   ;; would use a cache associated with the daemon connection instead (XXX).
   (make-hash-table 100))
 
+(define (references/cached store item)
+  "Like 'references', but cache results."
+  (or (hash-ref %reference-cache item)
+      (let ((references (references store item)))
+        (hash-set! %reference-cache item references)
+        references)))
+
 (define (references/substitutes store items)
   "Return the list of list of references of ITEMS; the result has the same
 length as ITEMS.  Query substitute information for any item missing from the