summaryrefslogtreecommitdiff
path: root/tests/testutil-wttrin.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-02-21 07:06:50 -0600
committerCraig Jennings <c@cjennings.net>2026-02-21 07:11:03 -0600
commitb74b98f177d92d50ddbede900ba41212e07c5f63 (patch)
tree459b1630dcc7d1c941f850565acdc16332831948 /tests/testutil-wttrin.el
parentec8130cfe1a7390e9939b311c8db39907a3f7f44 (diff)
downloademacs-wttrin-b74b98f177d92d50ddbede900ba41212e07c5f63.tar.gz
emacs-wttrin-b74b98f177d92d50ddbede900ba41212e07c5f63.zip
feat: unified cache and staleness handling for mode-line and buffer
Replace TTL-based cache invalidation with proactive scheduled refresh. Both mode-line and buffer systems now follow: timer refreshes cache, display reads from cache, staleness indicated when data is old. Phase 1 - Mode-line cache formalization + staleness display: - Replace wttrin--mode-line-tooltip-data with wttrin--mode-line-cache as (timestamp . data) cons cell matching buffer cache pattern - Add wttrin--format-age helper for human-readable age strings - Rewrite wttrin--mode-line-update-display to take no arguments, read from cache, compute staleness (age > 2x refresh interval), dim emoji gray when stale, show staleness info in tooltip - Rewrite wttrin--mode-line-fetch-weather to write cache on success, show stale display on failure with cache, error placeholder without - Add wttrin--mode-line-update-placeholder-error for first-launch failure Phase 2 - Remove TTL, add proactive buffer refresh: - Rename wttrin-cache-ttl to wttrin-refresh-interval (default 3600s) with define-obsolete-variable-alias for backward compatibility - Change wttrin-mode-line-refresh-interval default from 900 to 3600 - Remove TTL check from wttrin--get-cached-or-fetch; serve cached data regardless of age, background timer keeps it fresh - Add buffer refresh timer (wttrin--buffer-cache-refresh) Phase 3 - Buffer staleness display: - Add wttrin--format-staleness-header for buffer age display - Insert staleness line in wttrin--display-weather before instructions Phase 4 - Cleanup: - Remove all references to wttrin--mode-line-tooltip-data - Update README.org cache settings and mode-line documentation - Update tests for new API (198 tests across 21 files, all passing)
Diffstat (limited to 'tests/testutil-wttrin.el')
-rw-r--r--tests/testutil-wttrin.el15
1 files changed, 12 insertions, 3 deletions
diff --git a/tests/testutil-wttrin.el b/tests/testutil-wttrin.el
index 685cc09..42c8c21 100644
--- a/tests/testutil-wttrin.el
+++ b/tests/testutil-wttrin.el
@@ -72,10 +72,10 @@
`(let ((wttrin-unit-system ,unit-system))
,@body))
-(defmacro testutil-wttrin-with-cache-ttl (ttl &rest body)
- "Execute BODY with wttrin-cache-ttl temporarily set to TTL."
+(defmacro testutil-wttrin-with-refresh-interval (interval &rest body)
+ "Execute BODY with wttrin-refresh-interval temporarily set to INTERVAL."
(declare (indent 1))
- `(let ((wttrin-cache-ttl ,ttl))
+ `(let ((wttrin-refresh-interval ,interval))
,@body))
(defmacro testutil-wttrin-with-cache-max (max-entries &rest body)
@@ -110,6 +110,15 @@
(funcall callback nil)))))
,@body))
+;;; Mode-line Cache Helpers
+
+(defun testutil-wttrin-set-mode-line-cache (data &optional age-seconds)
+ "Set mode-line cache to DATA, optionally aged by AGE-SECONDS."
+ (let ((timestamp (if age-seconds
+ (- (float-time) age-seconds)
+ (float-time))))
+ (setq wttrin--mode-line-cache (cons timestamp data))))
+
;;; Test Setup and Teardown
(defun testutil-wttrin-setup ()