Subject: Re: bug#49033: 28.0.50; [PATCH] Feature suggestion, url-cache-expiry-alist to override expire time for cache pruning

From: Alex Bochannek <[email-masked]>
Date: Sat, 19 Jun 2021 12:24:00 -0700

Benjamin Riefenstahl <[email-masked]> writes:

> Hi Alex,
>
>>>> -                 ;; Twelve hours.
>>>> -                 (* 12 60 60))))
>>>> +                 gravatar-cache-ttl)))
>
>> Lars Ingebrigtsen <[email-masked]> 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!
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)))
-- 
Alex.