[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
06/06: publish: Remove expired cache entries when '--ttl' is used.
From: |
Ludovic Courtès |
Subject: |
06/06: publish: Remove expired cache entries when '--ttl' is used. |
Date: |
Tue, 18 Apr 2017 17:20:08 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit d72b42064b3cdeca7adbf13cce00faff5b61472a
Author: Ludovic Courtès <address@hidden>
Date: Tue Apr 18 23:12:35 2017 +0200
publish: Remove expired cache entries when '--ttl' is used.
* guix/scripts/publish.scm (narinfo-files): New procedure.
(render-narinfo/cached)[delete-file]: New procedure. Add call to
'maybe-remove-expired-cache-entries'.
* doc/guix.texi (Invoking guix publish): Document the interation between
--cache and --ttl.
---
doc/guix.texi | 6 ++++++
guix/scripts/publish.scm | 31 +++++++++++++++++++++++++++++--
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index bbb2ba7..f2eba59 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -6600,6 +6600,9 @@ The ``baking'' process is performed by worker threads.
By default, one
thread per CPU core is created, but this can be customized. See
@option{--workers} below.
+When @option{--ttl} is used, cached entries are automatically deleted
+when they have expired.
+
@item address@hidden
When @option{--cache} is used, request the allocation of @var{N} worker
threads to ``bake'' archives.
@@ -6614,6 +6617,9 @@ This allows the user's Guix to keep substitute
information in cache for
guarantee that the store items it provides will indeed remain available
for as long as @var{ttl}.
+Additionally, when @option{--cache} is used, cached entries that have
+not been accessed for @var{ttl} may be deleted.
+
@item address@hidden
Use @var{path} as the prefix for the URLs of ``nar'' files
(@pxref{Invoking guix archive, normalized archives}).
diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm
index 70d914d..9dc006e 100644
--- a/guix/scripts/publish.scm
+++ b/guix/scripts/publish.scm
@@ -50,11 +50,13 @@
#:use-module (guix store)
#:use-module ((guix serialization) #:select (write-file))
#:use-module (guix zlib)
+ #:use-module (guix cache)
#:use-module (guix ui)
#:use-module (guix scripts)
#:use-module ((guix utils)
#:select (with-atomic-file-output compressed-file?))
- #:use-module ((guix build utils) #:select (dump-port mkdir-p))
+ #:use-module ((guix build utils)
+ #:select (dump-port mkdir-p find-files))
#:export (%public-key
%private-key
@@ -365,6 +367,14 @@ at a time."
(run-single-baker item (lambda () exp ...)))
+(define (narinfo-files cache)
+ "Return the list of .narinfo files under CACHE."
+ (if (file-is-directory? cache)
+ (find-files cache
+ (lambda (file stat)
+ (string-suffix? ".narinfo" file)))
+ '()))
+
(define* (render-narinfo/cached store request hash
#:key ttl (compression %no-compression)
(nar-path "nar")
@@ -372,6 +382,14 @@ at a time."
"Respond to the narinfo request for REQUEST. If the narinfo is available in
CACHE, then send it; otherwise, return 404 and \"bake\" that nar and narinfo
requested using POOL."
+ (define (delete-entry narinfo)
+ ;; Delete NARINFO and the corresponding nar from CACHE.
+ (let ((nar (string-append (string-drop-right narinfo
+ (string-length ".narinfo"))
+ ".nar")))
+ (delete-file* narinfo)
+ (delete-file* nar)))
+
(let* ((item (hash-part->path store hash))
(compression (actual-compression item compression))
(cached (and (not (string-null? item))
@@ -398,7 +416,16 @@ requested using POOL."
(bake-narinfo+nar cache item
#:ttl ttl
#:compression compression
- #:nar-path nar-path)))
+ #:nar-path nar-path))
+
+ (when ttl
+ (single-baker 'cache-cleanup
+ (maybe-remove-expired-cache-entries cache
+ narinfo-files
+ #:entry-expiration
+ (file-expiration-time ttl)
+ #:delete-entry
delete-entry
+ #:cleanup-period ttl))))
(not-found request))
(else
(not-found request)))))
- branch master updated (54412eb -> d72b420), Ludovic Courtès, 2017/04/18
- 02/06: publish: Introduce 'actual-compression'., Ludovic Courtès, 2017/04/18
- 03/06: publish: Use 'sendfile' when possible., Ludovic Courtès, 2017/04/18
- 06/06: publish: Remove expired cache entries when '--ttl' is used.,
Ludovic Courtès <=
- 01/06: Add (guix workers)., Ludovic Courtès, 2017/04/18
- 05/06: Add (guix cache) and use it in (guix scripts substitute)., Ludovic Courtès, 2017/04/18
- 04/06: publish: Add '--cache' and '--workers'., Ludovic Courtès, 2017/04/18