diff options
| author | Don Williams <don.e.williams@gmail.com> | 2025-12-06 12:46:37 -0500 |
|---|---|---|
| committer | Don Williams <don.e.williams@gmail.com> | 2025-12-06 12:46:37 -0500 |
| commit | 75d256e3ce56abce1754c5182e61cdf6b50c3661 (patch) | |
| tree | c65927dbc8bbf32d226996ef11fc949efae26aec /config/hypr/UserScripts | |
| parent | 952d7deec41dde866e5c0053d3670257e796687a (diff) | |
Invalidate cache when changing units
On branch development
Your branch is up to date with 'origin/development'.
Changes to be committed:
modified: Weather.py
Diffstat (limited to 'config/hypr/UserScripts')
| -rwxr-xr-x | config/hypr/UserScripts/Weather.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/config/hypr/UserScripts/Weather.py b/config/hypr/UserScripts/Weather.py index 14256cfd..6061f696 100755 --- a/config/hypr/UserScripts/Weather.py +++ b/config/hypr/UserScripts/Weather.py @@ -224,6 +224,12 @@ def read_api_cache() -> Optional[Dict[str, Any]]: data = json.load(f) # Use ensure_dict for safety data_dict = ensure_dict(data) + + # Invalidate cache if units mismatch + if data_dict.get("units") != UNITS: + log_debug(f"Cache units '{data_dict.get('units')}' mismatch current '{UNITS}'.") + return None + timestamp_val = data_dict.get("timestamp", 0) timestamp = coerce_float(timestamp_val) or 0 if (time.time() - timestamp) <= CACHE_TTL_SECONDS: @@ -238,6 +244,7 @@ def write_api_cache(payload: Dict[str, Any]) -> None: try: ensure_cache_dir() payload["timestamp"] = time.time() + payload["units"] = UNITS with API_CACHE_PATH.open("w", encoding="utf-8") as f: json.dump(payload, f) except Exception as e: |
