[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] scratch/with-url 58ddde5 2/3: Prune the cache faster.
From: |
Lars Ingebrigtsen |
Subject: |
[Emacs-diffs] scratch/with-url 58ddde5 2/3: Prune the cache faster. |
Date: |
Mon, 23 Jan 2017 21:54:23 +0000 (UTC) |
branch: scratch/with-url
commit 58ddde579ef89ec18d893dca2cfb4e978a1f64fc
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>
Prune the cache faster.
---
lisp/url/with-url.el | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/lisp/url/with-url.el b/lisp/url/with-url.el
index 6b2d71c..7107c05 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))))))