summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2017-01-23 21:59:33 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2017-01-23 21:59:33 +0100
commit58ddde579ef89ec18d893dca2cfb4e978a1f64fc (patch)
treed9b40f07ec5be67cdad387224ac38c0337d4d153
parent5b5461382a4e7b364637f0ba45c0887288fdc8d7 (diff)
downloademacs-58ddde579ef89ec18d893dca2cfb4e978a1f64fc.tar.gz
Prune the cache faster.
-rw-r--r--lisp/url/with-url.el18
1 files changed, 10 insertions, 8 deletions
diff --git a/lisp/url/with-url.el b/lisp/url/with-url.el
index 6b2d71ccc9a..7107c050c16 100644
--- a/lisp/url/with-url.el
+++ b/lisp/url/with-url.el
@@ -826,14 +826,16 @@ If the headers don't allow caching, nothing will be done."
(with-url--prune-cache)))
(defun with-url--prune-cache ()
- (dolist (file (directory-files-recursively
- (expand-file-name "url/cached" user-emacs-directory)
- "\\`[a-z0-9]+\\'"))
- (with-temp-buffer
- (when (and (ignore-errors
- (insert-file-contents-literally file)
- t)
- (with-url--cached-expired-p))
+ ;; We delete files that are older than a day. It would perhaps be
+ ;; nicer to actually look at expiration dates and stuff, but doing
+ ;; so would be rather slow. In any case, best current practice for
+ ;; files without explicit Expires (etc) headers is to just store
+ ;; them for a day, so it's OK.
+ (let ((cutoff (time-subtract (current-time) (seconds-to-time (* 60 60 24)))))
+ (dolist (file (directory-files-recursively
+ (expand-file-name "url/cached" user-emacs-directory)
+ "\\`[a-z0-9]+\\'"))
+ (when (time-less-p (file-attribute-modification-time file) cutoff)
(ignore-errors
(delete-file file))))))