* bug#49033: 28.0.50; [PATCH] Feature suggestion, url-cache-expiry-alist to override expire time for cache pruning
@ 2021-06-15 5:40 Alex Bochannek
2021-06-15 14:11 ` Lars Ingebrigtsen
0 siblings, 1 reply; 12+ messages in thread
From: Alex Bochannek @ 2021-06-15 5:40 UTC (permalink / raw)
To: 49033
[-- Attachment #1: Type: text/plain, Size: 973 bytes --]
Hello!
I was looking at the Gravatar code and noticed Larsi's change last year
to disable the URL caching and instead use a hash table. I would like to
see the timeout for the hash table configurable again and this sent me
to the `url-cache-expired' and `url-cache-prune-cache' functions. It
appears that `url-cache-expired' is no longer used after the Gravatar
caching change, so I was wondering if maybe it could be useful to have a
more general, URL-specific expiry policy in the URL caching code. This
way, on-disk caching for, e.g., gravatar.com could be longer than for
the in-memory hash - right now expiry for the Gravatar memory cache is
12 hours, for the global disk cache it is 1 hour.
I wrote up the below and I am asking for feedback on it. I was
particularly concerned about back-forming the URL based on the cache
path and there really should be some test cases around that. I have done
minimal testing and I am open to suggestions to do this differently.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 1932 bytes --]
diff --git a/lisp/url/url-cache.el b/lisp/url/url-cache.el
index 830e6ba9dc..1bf5abcb51 100644
--- a/lisp/url/url-cache.el
+++ b/lisp/url/url-cache.el
@@ -38,6 +38,12 @@ url-cache-expire-time
:type 'integer
:group 'url-cache)
+(defcustom url-cache-expiry-alist nil
+ "Alist of URL regular expressions to override the `url-cache-expire-time'."
+ :version "28.1"
+ :type 'alist
+ :group 'url-cache)
+
;; Cache manager
(defun url-cache-file-writable-p (file)
"Follows the documentation of `file-writable-p', unlike `file-writable-p'."
@@ -186,6 +192,27 @@ url-cache-create-filename
(if (url-p url) url
(url-generic-parse-url url)))))
+(defun url-cache-create-url-from-file (file)
+ (if (file-exists-p file)
+ (let* ((url-path-list
+ (split-string
+ (string-trim-right
+ (string-trim-left
+ file
+ (concat "^.*/" (user-real-login-name)))
+ "/[^/]+$") "/" t))
+ (url-access-method
+ (pop url-path-list))
+ (url-domain-name
+ (string-join
+ (reverse url-path-list)
+ "."))
+ (url
+ (string-join
+ (list url-access-method url-domain-name)
+ "://")))
+ url)))
+
;;;###autoload
(defun url-cache-extract (fnam)
"Extract FNAM from the local disk cache."
@@ -226,7 +253,22 @@ url-cache-prune-cache
((time-less-p
(time-add
(file-attribute-modification-time (file-attributes file))
- url-cache-expire-time)
+ (or
+ (let ((expire-time
+ (remove
+ nil
+ (mapcar
+ (lambda (alist)
+ (let ((key (car alist))
+ (value (cdr alist)))
+ (if
+ (string-match
+ key
+ (url-cache-create-url-from-file file))
+ value)))
+ url-cache-expiry-alist))))
+ (if (consp expire-time) (apply 'min expire-time) nil))
+ url-cache-expire-time))
now)
(delete-file file)
(setq deleted-files (1+ deleted-files))))))
[-- Attachment #3: Type: text/plain, Size: 208 bytes --]
I also didn't really like the way the code ended up being formatted. Is
there some guidance around splitting functions and their arguments
across multiple lines?
For the Gravatar change, I had this in mind.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: Type: text/x-patch, Size: 1209 bytes --]
diff --git a/lisp/image/gravatar.el b/lisp/image/gravatar.el
index f6f056a2ba..6fea19d942 100644
--- a/lisp/image/gravatar.el
+++ b/lisp/image/gravatar.el
@@ -41,15 +41,14 @@ gravatar-automatic-caching
:group 'gravatar)
(make-obsolete-variable 'gravatar-automatic-caching nil "28.1")
-(defcustom gravatar-cache-ttl 2592000
+(defcustom gravatar-cache-ttl 43200
"Time to live in seconds for gravatar cache entries.
If a requested gravatar has been cached for longer than this, it
-is retrieved anew. The default value is 30 days."
+is retrieved anew. The default value is 12 hours."
:type 'integer
;; Restricted :type to number of seconds.
:version "27.1"
:group 'gravatar)
-(make-obsolete-variable 'gravatar-cache-ttl nil "28.1")
(defcustom gravatar-rating "g"
"Most explicit Gravatar rating level to allow.
@@ -287,8 +286,7 @@ gravatar-retrieve
(defun gravatar--prune-cache ()
(let ((expired nil)
(time (- (time-convert (current-time) 'integer)
- ;; Twelve hours.
- (* 12 60 60))))
+ gravatar-cache-ttl)))
(maphash (lambda (key val)
(when (< (car val) time)
(push key expired)))
[-- Attachment #5: Type: text/plain, Size: 19 bytes --]
Thanks!
--
Alex.
^ permalink raw reply related [flat|nested] 12+ messages in thread
* bug#49033: 28.0.50; [PATCH] Feature suggestion, url-cache-expiry-alist to override expire time for cache pruning
2021-06-15 5:40 bug#49033: 28.0.50; [PATCH] Feature suggestion, url-cache-expiry-alist to override expire time for cache pruning Alex Bochannek
@ 2021-06-15 14:11 ` Lars Ingebrigtsen
2021-06-15 22:55 ` Alex Bochannek
0 siblings, 1 reply; 12+ messages in thread
From: Lars Ingebrigtsen @ 2021-06-15 14:11 UTC (permalink / raw)
To: Alex Bochannek; +Cc: 49033
Alex Bochannek <alex@bochannek.com> writes:
> +(defcustom url-cache-expiry-alist nil
> + "Alist of URL regular expressions to override the `url-cache-expire-time'."
> + :version "28.1"
> + :type 'alist
> + :group 'url-cache)
Sure, adding this makes sense to me.
> +(defun url-cache-create-url-from-file (file)
I thought this existed, but I guess not...
> + (let ((expire-time
> + (remove
> + nil
> + (mapcar
> + (lambda (alist)
> + (let ((key (car alist))
> + (value (cdr alist)))
> + (if
> + (string-match
> + key
> + (url-cache-create-url-from-file file))
> + value)))
> + url-cache-expiry-alist))))
> + (if (consp expire-time) (apply 'min expire-time) nil))
> + url-cache-expire-time))
> now)
> (delete-file file)
> (setq deleted-files (1+ deleted-files))))))
>
> I also didn't really like the way the code ended up being formatted. Is
> there some guidance around splitting functions and their arguments
> across multiple lines?
Well, we never do:
> + (if
> + (string-match
But in general, we just try to keep it readable, which means not going
too far in either horizontal nor vertical directions. (So there's
really no rules for formatting beyond that.) Your code in this patch
generally seems to be way too vertical.
> - ;; Twelve hours.
> - (* 12 60 60))))
> + gravatar-cache-ttl)))
I don't mind that -- but is this really something that somebody would
want to control? It just seemed unlikely to me.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#49033: 28.0.50; [PATCH] Feature suggestion, url-cache-expiry-alist to override expire time for cache pruning
2021-06-15 14:11 ` Lars Ingebrigtsen
@ 2021-06-15 22:55 ` Alex Bochannek
2021-06-19 12:14 ` Lars Ingebrigtsen
2021-06-19 12:56 ` Benjamin Riefenstahl
0 siblings, 2 replies; 12+ messages in thread
From: Alex Bochannek @ 2021-06-15 22:55 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 49033
[-- Attachment #1: Type: text/plain, Size: 1165 bytes --]
Lars Ingebrigtsen <larsi@gnus.org> writes:
>> - ;; Twelve hours.
>> - (* 12 60 60))))
>> + gravatar-cache-ttl)))
>
> I don't mind that -- but is this really something that somebody would
> want to control? It just seemed unlikely to me.
I tend to find it difficult to reason about functionality if constants
like this are in the code and not in variables. It may be unlikely that
many people will want to customize it, but I'd rather expose this as a
configuration variable than hide a static value in the code.
As far as the URL caching code is concerned, I cleaned it up a bit and
added some simple tests and documentation.
Support URL-specific cache expiration
* test/lisp/url/url-cache-tests.el: Test URL-to-filename and
filename-to-URL mappings used by URL caching.
* lisp/url/url-cache.el (url-cache-expiry-alist)
(url-cache-create-url-from-file, url-cache-expired)
(url-cache-prune-cache): Expire cache entries based on regular
expressions matching URLs defined in new customizable variable
url-cache-expire-alist.
* doc/misc/url.texi (Disk Caching): Mention
url-cache-expiry-alist variable.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 5934 bytes --]
diff --git a/doc/misc/url.texi b/doc/misc/url.texi
index 8f15e11007..2ea34e0d03 100644
--- a/doc/misc/url.texi
+++ b/doc/misc/url.texi
@@ -923,6 +923,12 @@ Disk Caching
expire-time argument of the function @code{url-cache-expired}.
@end defopt
+@defopt url-cache-expiry-alist
+This variable is an alist of regular expressions matching @var{url}'s
+and their associated expiration delay in seconds. It is used by the
+functions @code{url-cache-expired} and @code{url-cache-prune-cache}.
+@end defopt
+
@defun url-fetch-from-cache
This function takes a URL as its argument and returns a buffer
containing the data cached for that URL.
diff --git a/lisp/url/url-cache.el b/lisp/url/url-cache.el
index 830e6ba9dc..48f315a5cc 100644
--- a/lisp/url/url-cache.el
+++ b/lisp/url/url-cache.el
@@ -38,6 +38,15 @@ url-cache-expire-time
:type 'integer
:group 'url-cache)
+(defcustom url-cache-expiry-alist nil
+ "Alist of URL regular expressions to override the `url-cache-expire-time'.
+The key is a string to be matched against the URL of the cached entry and the
+value is the expire time in seconds. Only the protocol and hostname of the URL
+are available for matching."
+ :version "28.1"
+ :type 'alist
+ :group 'url-cache)
+
;; Cache manager
(defun url-cache-file-writable-p (file)
"Follows the documentation of `file-writable-p', unlike `file-writable-p'."
@@ -186,6 +195,31 @@ url-cache-create-filename
(if (url-p url) url
(url-generic-parse-url url)))))
+(defun url-cache-create-url-from-file (file)
+ (let* ((url-path-list
+ (split-string
+ (file-name-directory
+ (string-trim-left file (concat "^.*/" (user-real-login-name))))
+ "/" t))
+ (protocol (pop url-path-list))
+ (hostname
+ (string-join (reverse url-path-list) "."))
+ (url (string-join (list protocol hostname) "://")))
+ url))
+
+(defun url-cache-expiry-by-url (url)
+ (let ((expire-time
+ (remove nil
+ (mapcar
+ (lambda (alist)
+ (let ((key (car alist))
+ (value (cdr alist)))
+ (if (string-match
+ key url)
+ value)))
+ url-cache-expiry-alist))))
+ (if (consp expire-time) (apply 'min expire-time) nil)))
+
;;;###autoload
(defun url-cache-extract (fnam)
"Extract FNAM from the local disk cache."
@@ -204,7 +238,9 @@ url-cache-expired
(time-less-p
(time-add
cache-time
- (or expire-time url-cache-expire-time))
+ (or expire-time
+ (url-cache-expiry-by-url url)
+ url-cache-expire-time))
nil)))))
(defun url-cache-prune-cache (&optional directory)
@@ -226,8 +262,10 @@ url-cache-prune-cache
((time-less-p
(time-add
(file-attribute-modification-time (file-attributes file))
- url-cache-expire-time)
- now)
+ (or (url-cache-expiry-by-url
+ (url-cache-create-url-from-file file))
+ url-cache-expire-time))
+ now)
(delete-file file)
(setq deleted-files (1+ deleted-files))))))
(if (< deleted-files total-files)
diff --git a/test/lisp/url/url-cache-tests.el b/test/lisp/url/url-cache-tests.el
new file mode 100644
index 0000000000..f4e49ce3b9
--- /dev/null
+++ b/test/lisp/url/url-cache-tests.el
@@ -0,0 +1,76 @@
+;;; url-cache-tests.el --- Test suite for url-cache. -*- lexical-binding:t -*-
+
+;; Copyright (C) 2021 Free Software Foundation, Inc.
+
+;; Author: Alex Bochannek <alex@bochannek.com>
+;; Keywords: data
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(require 'url-cache)
+
+(ert-deftest url-cache-url-to-filename-tests ()
+ "Test the URL to filename resolution for the URL cache"
+ (should (equal (file-name-directory
+ (url-cache-create-filename "http://www.fsf.co.uk"))
+ (string-join
+ (list url-cache-directory (user-real-login-name)
+ "http/uk/co/fsf/www/") "/")))
+ (should (equal (file-name-directory
+ (url-cache-create-filename "https://www.fsf.co.uk"))
+ (string-join
+ (list url-cache-directory (user-real-login-name)
+ "https/uk/co/fsf/www/") "/")))
+ (should (equal (file-name-directory
+ (url-cache-create-filename "http://host"))
+ (string-join
+ (list url-cache-directory (user-real-login-name)
+ "http/host/") "/")))
+ (should (equal (file-name-directory
+ (url-cache-create-filename "http://host:80"))
+ (string-join
+ (list url-cache-directory (user-real-login-name)
+ "http/host/") "/")))
+ (should (equal (file-name-directory
+ (url-cache-create-filename "http://host#fragment"))
+ (string-join
+ (list url-cache-directory (user-real-login-name)
+ "http/host/") "/"))))
+
+(ert-deftest url-cache-filename-to-url-tests ()
+ "Test the filename to URL resolution for the URL cache"
+ (should (equal (url-cache-create-url-from-file
+ (string-join
+ (list url-cache-directory (user-real-login-name)
+ "http/uk/co/fsf/www/") "/"))
+ "http://www.fsf.co.uk"))
+ (should (equal (url-cache-create-url-from-file
+ (string-join
+ (list url-cache-directory (user-real-login-name)
+ "https/uk/co/fsf/www/") "/"))
+ "https://www.fsf.co.uk"))
+ (should (equal (url-cache-create-url-from-file
+ (string-join
+ (list url-cache-directory (user-real-login-name)
+ "http/host/") "/"))
+ "http://host")))
+
+(provide 'url-cache-tests)
+
+;;; url-cache-tests.el ends here
[-- Attachment #3: Type: text/plain, Size: 10 bytes --]
--
Alex.
^ permalink raw reply related [flat|nested] 12+ messages in thread
* bug#49033: 28.0.50; [PATCH] Feature suggestion, url-cache-expiry-alist to override expire time for cache pruning
2021-06-15 22:55 ` Alex Bochannek
@ 2021-06-19 12:14 ` Lars Ingebrigtsen
2021-06-19 19:32 ` Alex Bochannek
2021-06-19 12:56 ` Benjamin Riefenstahl
1 sibling, 1 reply; 12+ messages in thread
From: Lars Ingebrigtsen @ 2021-06-19 12:14 UTC (permalink / raw)
To: Alex Bochannek; +Cc: 49033
Alex Bochannek <alex@bochannek.com> writes:
> I tend to find it difficult to reason about functionality if constants
> like this are in the code and not in variables. It may be unlikely that
> many people will want to customize it, but I'd rather expose this as a
> configuration variable than hide a static value in the code.
Adding user options to control things nobody has asked about isn't
helpful.
> Support URL-specific cache expiration
>
> * test/lisp/url/url-cache-tests.el: Test URL-to-filename and
> filename-to-URL mappings used by URL caching.
>
> * lisp/url/url-cache.el (url-cache-expiry-alist)
> (url-cache-create-url-from-file, url-cache-expired)
> (url-cache-prune-cache): Expire cache entries based on regular
> expressions matching URLs defined in new customizable variable
> url-cache-expire-alist.
>
> * doc/misc/url.texi (Disk Caching): Mention
> url-cache-expiry-alist variable.
Looks good to me. What's the use case for this, though?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#49033: 28.0.50; [PATCH] Feature suggestion, url-cache-expiry-alist to override expire time for cache pruning
2021-06-19 12:14 ` Lars Ingebrigtsen
@ 2021-06-19 19:32 ` Alex Bochannek
2021-06-21 12:21 ` Lars Ingebrigtsen
0 siblings, 1 reply; 12+ messages in thread
From: Alex Bochannek @ 2021-06-19 19:32 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 49033
Lars Ingebrigtsen <larsi@gnus.org> writes:
> Alex Bochannek <alex@bochannek.com> writes:
>
>> Support URL-specific cache expiration
>>
>> * test/lisp/url/url-cache-tests.el: Test URL-to-filename and
>> filename-to-URL mappings used by URL caching.
>>
>> * lisp/url/url-cache.el (url-cache-expiry-alist)
>> (url-cache-create-url-from-file, url-cache-expired)
>> (url-cache-prune-cache): Expire cache entries based on regular
>> expressions matching URLs defined in new customizable variable
>> url-cache-expire-alist.
>>
>> * doc/misc/url.texi (Disk Caching): Mention
>> url-cache-expiry-alist variable.
>
> Looks good to me. What's the use case for this, though?
I originally had looked at this for Gravatar entries and I am now using
it to avoid fetching the same images in RSS feeds. I just noticed though
that `url-cache-create-url-from-file' won't work if
`url-cache-create-filename-human-readable' is used. Any suggestions for
how to address that?
--
Alex.
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#49033: 28.0.50; [PATCH] Feature suggestion, url-cache-expiry-alist to override expire time for cache pruning
2021-06-19 19:32 ` Alex Bochannek
@ 2021-06-21 12:21 ` Lars Ingebrigtsen
2021-06-21 18:25 ` Alex Bochannek
0 siblings, 1 reply; 12+ messages in thread
From: Lars Ingebrigtsen @ 2021-06-21 12:21 UTC (permalink / raw)
To: Alex Bochannek; +Cc: 49033
Alex Bochannek <alex@bochannek.com> writes:
> I originally had looked at this for Gravatar entries and I am now using
> it to avoid fetching the same images in RSS feeds.
Right; makes sense.
> I just noticed though that `url-cache-create-url-from-file' won't work
> if `url-cache-create-filename-human-readable' is used. Any suggestions
> for how to address that?
No, sorry -- I'm pretty unfamiliar with the url-cache code.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#49033: 28.0.50; [PATCH] Feature suggestion, url-cache-expiry-alist to override expire time for cache pruning
2021-06-21 12:21 ` Lars Ingebrigtsen
@ 2021-06-21 18:25 ` Alex Bochannek
2021-10-24 7:27 ` Stefan Kangas
0 siblings, 1 reply; 12+ messages in thread
From: Alex Bochannek @ 2021-06-21 18:25 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 49033
Lars Ingebrigtsen <larsi@gnus.org> writes:
> Alex Bochannek <alex@bochannek.com> writes:
>
>> I originally had looked at this for Gravatar entries and I am now using
>> it to avoid fetching the same images in RSS feeds.
>
> Right; makes sense.
>
>> I just noticed though that `url-cache-create-url-from-file' won't work
>> if `url-cache-create-filename-human-readable' is used. Any suggestions
>> for how to address that?
>
> No, sorry -- I'm pretty unfamiliar with the url-cache code.
I need to think about this some more. The easy way is to not try to
recreate the URL but to have users specify the path for cache entries. I
might just do that and see how that works out for me in practice. Either
way, it's not ready for merging yet.
Thanks!
--
Alex.
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#49033: 28.0.50; [PATCH] Feature suggestion, url-cache-expiry-alist to override expire time for cache pruning
2021-06-21 18:25 ` Alex Bochannek
@ 2021-10-24 7:27 ` Stefan Kangas
2021-10-27 16:36 ` Alex Bochannek
0 siblings, 1 reply; 12+ messages in thread
From: Stefan Kangas @ 2021-10-24 7:27 UTC (permalink / raw)
To: Alex Bochannek; +Cc: Lars Ingebrigtsen, 49033
Alex Bochannek <alex@bochannek.com> writes:
> Lars Ingebrigtsen <larsi@gnus.org> writes:
>
>> Alex Bochannek <alex@bochannek.com> writes:
>>
>>> I originally had looked at this for Gravatar entries and I am now using
>>> it to avoid fetching the same images in RSS feeds.
>>
>> Right; makes sense.
>>
>>> I just noticed though that `url-cache-create-url-from-file' won't work
>>> if `url-cache-create-filename-human-readable' is used. Any suggestions
>>> for how to address that?
>>
>> No, sorry -- I'm pretty unfamiliar with the url-cache code.
>
> I need to think about this some more. The easy way is to not try to
> recreate the URL but to have users specify the path for cache entries. I
> might just do that and see how that works out for me in practice. Either
> way, it's not ready for merging yet.
(That was 17 weeks ago.)
Did you get any further here? Thanks in advance.
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#49033: 28.0.50; [PATCH] Feature suggestion, url-cache-expiry-alist to override expire time for cache pruning
2021-10-24 7:27 ` Stefan Kangas
@ 2021-10-27 16:36 ` Alex Bochannek
2021-10-27 16:50 ` Stefan Kangas
0 siblings, 1 reply; 12+ messages in thread
From: Alex Bochannek @ 2021-10-27 16:36 UTC (permalink / raw)
To: Stefan Kangas; +Cc: Lars Ingebrigtsen, 49033
Stefan,
Stefan Kangas <stefan@marxist.se> writes:
> Alex Bochannek <alex@bochannek.com> writes:
>
>> Lars Ingebrigtsen <larsi@gnus.org> writes:
>>
>>> Alex Bochannek <alex@bochannek.com> writes:
>>>
>>>> I originally had looked at this for Gravatar entries and I am now using
>>>> it to avoid fetching the same images in RSS feeds.
>>>
>>> Right; makes sense.
>>>
>>>> I just noticed though that `url-cache-create-url-from-file' won't work
>>>> if `url-cache-create-filename-human-readable' is used. Any suggestions
>>>> for how to address that?
>>>
>>> No, sorry -- I'm pretty unfamiliar with the url-cache code.
>>
>> I need to think about this some more. The easy way is to not try to
>> recreate the URL but to have users specify the path for cache entries. I
>> might just do that and see how that works out for me in practice. Either
>> way, it's not ready for merging yet.
>
> (That was 17 weeks ago.)
>
> Did you get any further here? Thanks in advance.
I did not have a chance to work on this any further. The problem here is
that the way URLs are mapped to a directory structure does not allow for
a reliable backwards mapping. A thought I had about this was to keep an
intermediate mapping for URLs to cache files around in the cache
itself. Might be interesting to see how browsers solve this in general
as not to reinvent the wheel.
If this is something you would want to work on, please feel free to do
so! I don't think I will have uninterrupted time to focus on this until
the end of the year.
--
Alex.
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#49033: 28.0.50; [PATCH] Feature suggestion, url-cache-expiry-alist to override expire time for cache pruning
2021-10-27 16:36 ` Alex Bochannek
@ 2021-10-27 16:50 ` Stefan Kangas
0 siblings, 0 replies; 12+ messages in thread
From: Stefan Kangas @ 2021-10-27 16:50 UTC (permalink / raw)
To: Alex Bochannek; +Cc: Lars Ingebrigtsen, 49033
Alex Bochannek <alex@bochannek.com> writes:
> If this is something you would want to work on, please feel free to do
> so! I don't think I will have uninterrupted time to focus on this until
> the end of the year.
No problem, there is no rush with this. I was only checking in.
I currently have too many other projects to be able to take this on. So
I guess the best chance for anything to happen here is for you to get to
it when you find the time. If you do, it will be much appreciated.
Thanks!
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#49033: 28.0.50; [PATCH] Feature suggestion, url-cache-expiry-alist to override expire time for cache pruning
2021-06-15 22:55 ` Alex Bochannek
2021-06-19 12:14 ` Lars Ingebrigtsen
@ 2021-06-19 12:56 ` Benjamin Riefenstahl
2021-06-19 19:24 ` Alex Bochannek
1 sibling, 1 reply; 12+ messages in thread
From: Benjamin Riefenstahl @ 2021-06-19 12:56 UTC (permalink / raw)
To: Alex Bochannek; +Cc: Lars Ingebrigtsen, 49033
Hi Alex,
>>> - ;; Twelve hours.
>>> - (* 12 60 60))))
>>> + gravatar-cache-ttl)))
> Lars Ingebrigtsen <larsi@gnus.org> writes:
>> I don't mind that -- but is this really something that somebody would
>> want to control? It just seemed unlikely to me.
Alex Bochannek writes:
> I tend to find it difficult to reason about functionality if constants
> like this are in the code and not in variables.
Maybe use defconst instead?
Just a drive-by thought,
benny
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#49033: 28.0.50; [PATCH] Feature suggestion, url-cache-expiry-alist to override expire time for cache pruning
2021-06-19 12:56 ` Benjamin Riefenstahl
@ 2021-06-19 19:24 ` Alex Bochannek
0 siblings, 0 replies; 12+ messages in thread
From: Alex Bochannek @ 2021-06-19 19:24 UTC (permalink / raw)
To: Benjamin Riefenstahl; +Cc: Lars Ingebrigtsen, 49033
[-- Attachment #1: Type: text/plain, Size: 661 bytes --]
Benjamin Riefenstahl <b.riefenstahl@turtle-trading.net> writes:
> Hi Alex,
>
>>>> - ;; Twelve hours.
>>>> - (* 12 60 60))))
>>>> + gravatar-cache-ttl)))
>
>> Lars Ingebrigtsen <larsi@gnus.org> writes:
>>> I don't mind that -- but is this really something that somebody would
>>> want to control? It just seemed unlikely to me.
>
> Alex Bochannek writes:
>> I tend to find it difficult to reason about functionality if constants
>> like this are in the code and not in variables.
>
> Maybe use defconst instead?
>
> Just a drive-by thought,
> benny
I like that idea, that seems like a good compromise.
Thanks!
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 899 bytes --]
diff --git a/lisp/image/gravatar.el b/lisp/image/gravatar.el
index f6f056a2ba..ebae356e26 100644
--- a/lisp/image/gravatar.el
+++ b/lisp/image/gravatar.el
@@ -51,6 +51,9 @@ gravatar-cache-ttl
:group 'gravatar)
(make-obsolete-variable 'gravatar-cache-ttl nil "28.1")
+(defconst gravatar-cache-expiry (* 12 60 60)
+ "Time to live for gravatar cache entries (12 hours.)")
+
(defcustom gravatar-rating "g"
"Most explicit Gravatar rating level to allow.
Some gravatars are rated according to how suitable they are for
@@ -287,8 +290,7 @@ gravatar-retrieve
(defun gravatar--prune-cache ()
(let ((expired nil)
(time (- (time-convert (current-time) 'integer)
- ;; Twelve hours.
- (* 12 60 60))))
+ gravatar-cache-expiry)))
(maphash (lambda (key val)
(when (< (car val) time)
(push key expired)))
[-- Attachment #3: Type: text/plain, Size: 10 bytes --]
--
Alex.
^ permalink raw reply related [flat|nested] 12+ messages in thread
end of thread, other threads:[~2021-10-27 16:50 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-15 5:40 bug#49033: 28.0.50; [PATCH] Feature suggestion, url-cache-expiry-alist to override expire time for cache pruning Alex Bochannek
2021-06-15 14:11 ` Lars Ingebrigtsen
2021-06-15 22:55 ` Alex Bochannek
2021-06-19 12:14 ` Lars Ingebrigtsen
2021-06-19 19:32 ` Alex Bochannek
2021-06-21 12:21 ` Lars Ingebrigtsen
2021-06-21 18:25 ` Alex Bochannek
2021-10-24 7:27 ` Stefan Kangas
2021-10-27 16:36 ` Alex Bochannek
2021-10-27 16:50 ` Stefan Kangas
2021-06-19 12:56 ` Benjamin Riefenstahl
2021-06-19 19:24 ` Alex Bochannek
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.