aboutsummaryrefslogtreecommitdiff
path: root/wttrin.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-28 03:50:53 -0400
committerCraig Jennings <c@cjennings.net>2026-06-28 03:50:53 -0400
commit944a52f0e33087dafba383edb3d97ec19a06d361 (patch)
tree53528fb582b2b3fa044d02cb46c57390f50924b4 /wttrin.el
parent38b7812b3bce45372fd2f11a8da710cb73717092 (diff)
downloademacs-wttrin-944a52f0e33087dafba383edb3d97ec19a06d361.tar.gz
emacs-wttrin-944a52f0e33087dafba383edb3d97ec19a06d361.zip
fix: key the cache on all response-shaping settings
wttrin--make-cache-key keyed only on location and unit system, but the request body also depends on wttrin-display-options and wttrin-default-languages. Changing display options or language mid-session served the old cached response, and the staleness header then claimed it was current for the new settings. The key now includes every setting that shapes the response. Cache-key tests rewritten to assert behavior (distinct key per varying setting, stable key for identical settings) instead of an exact key string.
Diffstat (limited to 'wttrin.el')
-rw-r--r--wttrin.el9
1 files changed, 7 insertions, 2 deletions
diff --git a/wttrin.el b/wttrin.el
index 3d543ed..cdef10a 100644
--- a/wttrin.el
+++ b/wttrin.el
@@ -1236,8 +1236,13 @@ coordinates from a geolocation command."
(wttrin--display-weather query raw-string error-msg display address)))))))
(defun wttrin--make-cache-key (location)
- "Create cache key from LOCATION and current settings."
- (concat location "|" (or wttrin-unit-system "default")))
+ "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."
+ (format "%S" (list location
+ (or wttrin-unit-system "default")
+ (or wttrin-display-options "")
+ wttrin-default-languages)))
(defun wttrin--get-cached-or-fetch (location callback)
"Get cached weather for LOCATION or fetch if not cached.