summary refs log tree commit diff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2023-05-31 23:02:16 +0200
committerLudovic Courtès <ludo@gnu.org>2023-06-08 22:27:20 +0200
commit3f5e14182931f123c10513a3e1e2abaebfb52279 (patch)
tree5a1c9161bad12e75f9b2a68a99f2b14f3fda37af
parent92ee0fd5eb7b1572cd4f90a7c12c1137ce74004b (diff)
downloadguix-3f5e14182931f123c10513a3e1e2abaebfb52279.tar.gz
substitute: Delete cached narinfos more than two-month old.
This allows 'guix substitute' to shrink the cache a bit more, which
saves space and improves performance of cache-cleanup phases since fewer
entries need to be traversed.

* guix/scripts/substitute.scm (cached-narinfo-expiration-time): Define
'max-ttl' and use it as an upper bound.
-rwxr-xr-xguix/scripts/substitute.scm9
1 files changed, 7 insertions, 2 deletions
diff --git a/guix/scripts/substitute.scm b/guix/scripts/substitute.scm
index 3626832dda..de7b77b0bf 100755
--- a/guix/scripts/substitute.scm
+++ b/guix/scripts/substitute.scm
@@ -167,6 +167,11 @@ was found."
 
 (define (cached-narinfo-expiration-time file)
   "Return the expiration time for FILE, which is a cached narinfo."
+  (define max-ttl
+    ;; Upper bound on the TTL used to avoid keeping around cached narinfos for
+    ;; too long, which makes the cache bigger and more expensive to traverse.
+    (* 2 30 24 60 60))                            ;2 months
+
   (catch 'system-error
     (lambda ()
       (call-with-input-file file
@@ -174,10 +179,10 @@ was found."
           (match (read port)
             (('narinfo ('version 2) ('cache-uri uri)
                        ('date date) ('ttl ttl) ('value #f))
-             (+ date ttl))
+             (+ date (min ttl max-ttl)))
             (('narinfo ('version 2) ('cache-uri uri)
                        ('date date) ('ttl ttl) ('value value))
-             (+ date ttl))
+             (+ date (min ttl max-ttl)))
             (x
              0)))))
     (lambda args