From 752e2f825b1ee3eb513e27f2c03bcaef30eec767 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 4 Apr 2026 13:24:01 -0500 Subject: fix: cache timestamp reflects request time, not response time float-time was captured in the outer let* before the async fetch. The callback used this stale value, making cache entries appear slightly older than they are. Move the float-time call into the callback so the timestamp reflects when the data actually arrived. --- wttrin.el | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'wttrin.el') diff --git a/wttrin.el b/wttrin.el index d95f0c2..c2cb74d 100644 --- a/wttrin.el +++ b/wttrin.el @@ -444,8 +444,7 @@ regardless of age. The background refresh timer keeps data fresh. CALLBACK is called with the weather data string when ready, or nil on error." (let* ((cache-key (wttrin--make-cache-key location)) (cached (gethash cache-key wttrin--cache)) - (data (cdr cached)) - (now (float-time))) + (data (cdr cached))) (if (and cached (not wttrin--force-refresh)) ;; Return cached data immediately regardless of age (funcall callback data) @@ -456,7 +455,7 @@ CALLBACK is called with the weather data string when ready, or nil on error." (if fresh-data (progn (wttrin--cleanup-cache-if-needed) - (puthash cache-key (cons now fresh-data) wttrin--cache) + (puthash cache-key (cons (float-time) fresh-data) wttrin--cache) (funcall callback fresh-data)) ;; On error, return stale cache if available (if cached -- cgit v1.2.3