From 9c8d23eeddb72590234a424b449611256a540527 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 13 Sep 2026 09:46:11 -0500 Subject: fix: key the cache on the effective display options wttrin--make-cache-key used the raw wttrin-display-options, so turning wttrin-hide-follow-line on or off produced the same key. A cached location then kept serving the old buffer with the Follow line. Nothing refreshes a non-favorite location in the background, so it stayed wrong until a forced refresh or eviction. The key now uses wttrin--effective-display-options, the flags actually sent to wttr.in. Two tests pin it: the toggle changes the key, and the toggle and an explicit F flag share one key because they send the same request. --- tests/test-wttrin--make-cache-key.el | 19 +++++++++++++++++++ wttrin.el | 6 ++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/test-wttrin--make-cache-key.el b/tests/test-wttrin--make-cache-key.el index 79c78d9..f1aca85 100644 --- a/tests/test-wttrin--make-cache-key.el +++ b/tests/test-wttrin--make-cache-key.el @@ -62,6 +62,25 @@ Without this, changing the forecast format keeps serving the old cached output." (should-not (string= a c)) (should-not (string= b c)))) +;; wttrin-hide-follow-line changes the request (it adds the F flag), so it +;; has to change the key too. Keying on the raw options string missed it and +;; served a cached buffer that still showed the Follow line. +(ert-deftest test-wttrin--make-cache-key-boundary-hide-follow-line-changes-key () + "Boundary: turning `wttrin-hide-follow-line' on or off yields a distinct key." + (let ((off (let ((wttrin-display-options nil) (wttrin-hide-follow-line nil)) + (wttrin--make-cache-key "Paris"))) + (on (let ((wttrin-display-options nil) (wttrin-hide-follow-line t)) + (wttrin--make-cache-key "Paris")))) + (should-not (string= off on)))) + +(ert-deftest test-wttrin--make-cache-key-boundary-equivalent-requests-share-key () + "Boundary: the toggle and an explicit F flag send one request, so one key." + (let ((toggle (let ((wttrin-display-options nil) (wttrin-hide-follow-line t)) + (wttrin--make-cache-key "Paris"))) + (flag (let ((wttrin-display-options "F") (wttrin-hide-follow-line nil)) + (wttrin--make-cache-key "Paris")))) + (should (string= toggle flag)))) + (ert-deftest test-wttrin--make-cache-key-boundary-language-changes-key () "Boundary: changing Accept-Language yields a distinct key." (let ((en (let ((wttrin-default-languages '("Accept-Language" . "en-US"))) diff --git a/wttrin.el b/wttrin.el index bc67924..812a5a9 100644 --- a/wttrin.el +++ b/wttrin.el @@ -1522,10 +1522,12 @@ coordinates from a geolocation command." (defun wttrin--make-cache-key (location) "Create a cache key from LOCATION and every setting that shapes the response. Includes the unit system, display options, and Accept-Language, so changing any -of them produces a distinct key rather than serving a stale-format response." +of them produces a distinct key rather than serving a stale-format response. +The display options are the effective ones sent to wttr.in, so +`wttrin-hide-follow-line' changes the key and an equivalent request shares it." (format "%S" (list location (or wttrin-unit-system "default") - (or wttrin-display-options "") + (wttrin--effective-display-options) wttrin-default-languages))) (defun wttrin--get-cached-or-fetch (location callback) -- cgit v1.2.3