From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alex Bochannek Newsgroups: gmane.emacs.bugs Subject: bug#49033: 28.0.50; [PATCH] Feature suggestion, url-cache-expiry-alist to override expire time for cache pruning Date: Mon, 14 Jun 2021 22:40:29 -0700 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="676"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (darwin) To: 49033@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jun 15 07:41:13 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lt1p3-000AWx-Cj for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 15 Jun 2021 07:41:13 +0200 Original-Received: from localhost ([::1]:40864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt1p2-0001JC-CB for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 15 Jun 2021 01:41:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41414) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt1ow-0001Iw-1Z for bug-gnu-emacs@gnu.org; Tue, 15 Jun 2021 01:41:06 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36720) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt1os-00062y-3A for bug-gnu-emacs@gnu.org; Tue, 15 Jun 2021 01:41:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lt1or-0006Ak-SN for bug-gnu-emacs@gnu.org; Tue, 15 Jun 2021 01:41:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alex Bochannek Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 15 Jun 2021 05:41:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 49033 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.162373564623696 (code B ref -1); Tue, 15 Jun 2021 05:41:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 15 Jun 2021 05:40:46 +0000 Original-Received: from localhost ([127.0.0.1]:48266 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lt1ob-0006A8-Vj for submit@debbugs.gnu.org; Tue, 15 Jun 2021 01:40:46 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:56600) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lt1oa-0006A0-9K for submit@debbugs.gnu.org; Tue, 15 Jun 2021 01:40:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt1oa-0001Ib-0u for bug-gnu-emacs@gnu.org; Tue, 15 Jun 2021 01:40:44 -0400 Original-Received: from ns.lapseofthought.com ([50.0.39.240]:41118 helo=mail.lapseofthought.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt1oV-0005k9-O6 for bug-gnu-emacs@gnu.org; Tue, 15 Jun 2021 01:40:43 -0400 Original-Received: from awb-mbp.local (unknown [IPv6:2601:646:4200:b470:ecdd:e5a6:220a:9156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.lapseofthought.com (Postfix) with ESMTPSA id 4G3xxB0SyNz3pdqB for ; Mon, 14 Jun 2021 22:40:30 -0700 (PDT) Authentication-Results: ORIGINATING; auth=pass smtp.auth=alex smtp.mailfrom=alex@bochannek.com Received-SPF: pass client-ip=50.0.39.240; envelope-from=alex@bochannek.com; helo=mail.lapseofthought.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:208525 Archived-At: --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline 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)))))) --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline 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))) --=-=-= Content-Type: text/plain Thanks! -- Alex. --=-=-=--