diff options
| author | Lars Ingebrigtsen | 2012-02-06 22:06:15 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2012-02-06 22:06:15 +0100 |
| commit | 1968bb1b5cc35ba315a741ad27de71e04b6c5aa2 (patch) | |
| tree | 94b597677aa117f696a7673750dea38073710d54 | |
| parent | c1f1086866d10a823a5ce59f286b3102716bfb42 (diff) | |
| download | emacs-1968bb1b5cc35ba315a741ad27de71e04b6c5aa2.tar.gz emacs-1968bb1b5cc35ba315a741ad27de71e04b6c5aa2.zip | |
Expire URL items from the on-disk cache once in a while
* url.el (url-retrieve-number-of-calls): New variable.
(url-retrieve-internal): Use it to expire the cache once in a
while.
* url-cache.el (url-cache-prune-cache): New function.
| -rw-r--r-- | lisp/url/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/url/url-cache.el | 26 | ||||
| -rw-r--r-- | lisp/url/url.el | 7 |
3 files changed, 39 insertions, 0 deletions
diff --git a/lisp/url/ChangeLog b/lisp/url/ChangeLog index 9285961fb32..4e748fbd99e 100644 --- a/lisp/url/ChangeLog +++ b/lisp/url/ChangeLog | |||
| @@ -1,5 +1,11 @@ | |||
| 1 | 2012-02-06 Lars Ingebrigtsen <larsi@gnus.org> | 1 | 2012-02-06 Lars Ingebrigtsen <larsi@gnus.org> |
| 2 | 2 | ||
| 3 | * url-cache.el (url-cache-prune-cache): New function. | ||
| 4 | |||
| 5 | * url.el (url-retrieve-number-of-calls): New variable. | ||
| 6 | (url-retrieve-internal): Use it to expire the cache once in a | ||
| 7 | while. | ||
| 8 | |||
| 3 | * url-queue.el (url-queue-setup-runners): New function that uses | 9 | * url-queue.el (url-queue-setup-runners): New function that uses |
| 4 | `run-with-idle-timer' for extra asynchronicity. | 10 | `run-with-idle-timer' for extra asynchronicity. |
| 5 | (url-queue-remove-jobs-from-host): New function. | 11 | (url-queue-remove-jobs-from-host): New function. |
diff --git a/lisp/url/url-cache.el b/lisp/url/url-cache.el index 20602a2f8ef..8fec2495675 100644 --- a/lisp/url/url-cache.el +++ b/lisp/url/url-cache.el | |||
| @@ -209,6 +209,32 @@ If `url-standalone-mode' is non-nil, cached items never expire." | |||
| 209 | (seconds-to-time (or expire-time url-cache-expire-time))) | 209 | (seconds-to-time (or expire-time url-cache-expire-time))) |
| 210 | (current-time)))))) | 210 | (current-time)))))) |
| 211 | 211 | ||
| 212 | (defun url-cache-prune-cache (&optional directory) | ||
| 213 | "Remove all expired files from the cache. | ||
| 214 | `url-cache-expire-time' says how old a file has to be to be | ||
| 215 | considered \"expired\"." | ||
| 216 | (let ((current-time (current-time)) | ||
| 217 | (total-files 0) | ||
| 218 | (deleted-files 0)) | ||
| 219 | (dolist (file (directory-files (or directory url-cache-directory) t)) | ||
| 220 | (unless (member (file-name-nondirectory file) '("." "..")) | ||
| 221 | (setq total-files (1+ total-files)) | ||
| 222 | (cond | ||
| 223 | ((file-directory-p file) | ||
| 224 | (when (url-cache-prune-cache file) | ||
| 225 | (setq deleted-files (1+ deleted-files)))) | ||
| 226 | ((time-less-p | ||
| 227 | (time-add | ||
| 228 | (nth 5 (file-attributes file)) | ||
| 229 | (seconds-to-time url-cache-expire-time)) | ||
| 230 | current-time) | ||
| 231 | (delete-file file) | ||
| 232 | (setq deleted-files (1+ deleted-files)))))) | ||
| 233 | (if (< deleted-files total-files) | ||
| 234 | nil | ||
| 235 | (delete-directory directory) | ||
| 236 | t))) | ||
| 237 | |||
| 212 | (provide 'url-cache) | 238 | (provide 'url-cache) |
| 213 | 239 | ||
| 214 | ;;; url-cache.el ends here | 240 | ;;; url-cache.el ends here |
diff --git a/lisp/url/url.el b/lisp/url/url.el index 883e1a0c765..03b66b15232 100644 --- a/lisp/url/url.el +++ b/lisp/url/url.el | |||
| @@ -119,6 +119,9 @@ Sometimes while retrieving a URL, the URL library needs to use another buffer | |||
| 119 | than the one returned initially by `url-retrieve'. In this case, it sets this | 119 | than the one returned initially by `url-retrieve'. In this case, it sets this |
| 120 | variable in the original buffer as a forwarding pointer.") | 120 | variable in the original buffer as a forwarding pointer.") |
| 121 | 121 | ||
| 122 | (defvar url-retrieve-number-of-calls 0) | ||
| 123 | (autoload 'url-cache-prune-cache "url-cache") | ||
| 124 | |||
| 122 | ;;;###autoload | 125 | ;;;###autoload |
| 123 | (defun url-retrieve (url callback &optional cbargs silent) | 126 | (defun url-retrieve (url callback &optional cbargs silent) |
| 124 | "Retrieve URL asynchronously and call CALLBACK with CBARGS when finished. | 127 | "Retrieve URL asynchronously and call CALLBACK with CBARGS when finished. |
| @@ -174,6 +177,10 @@ If SILENT, don't message progress reports and the like." | |||
| 174 | (unless (url-type url) | 177 | (unless (url-type url) |
| 175 | (error "Bad url: %s" (url-recreate-url url))) | 178 | (error "Bad url: %s" (url-recreate-url url))) |
| 176 | (setf (url-silent url) silent) | 179 | (setf (url-silent url) silent) |
| 180 | ;; Once in a while, remove old entries from the URL cache. | ||
| 181 | (when (zerop (% url-retrieve-number-of-calls 1000)) | ||
| 182 | (url-cache-prune-cache)) | ||
| 183 | (setq url-retrieve-number-of-calls (1+ url-retrieve-number-of-calls)) | ||
| 177 | (let ((loader (url-scheme-get-property (url-type url) 'loader)) | 184 | (let ((loader (url-scheme-get-property (url-type url) 'loader)) |
| 178 | (url-using-proxy (if (url-host url) | 185 | (url-using-proxy (if (url-host url) |
| 179 | (url-find-proxy-for-url url (url-host url)))) | 186 | (url-find-proxy-for-url url (url-host url)))) |