From c9c8ffc1f7e1cd1488543a0c90047301f7377b8d Mon Sep 17 00:00:00 2001 From: Ian Renton Date: Sat, 19 Sep 2026 08:04:50 +0100 Subject: [PATCH] If cache load fails because objects are from a different version and throw an exception, clear the cache. --- core/live_data_cache.py | 7 ++++++- core/single_object_data_cache.py | 8 +++++++- templates/add_spot.html | 2 +- templates/alerts.html | 2 +- templates/bands.html | 4 ++-- templates/base.html | 10 +++++----- templates/conditions.html | 2 +- templates/map.html | 4 ++-- templates/spots.html | 4 ++-- templates/status.html | 2 +- 10 files changed, 28 insertions(+), 17 deletions(-) diff --git a/core/live_data_cache.py b/core/live_data_cache.py index 6fb61e4..34e35d8 100644 --- a/core/live_data_cache.py +++ b/core/live_data_cache.py @@ -77,7 +77,12 @@ class LiveDataCache: logger.exception(f"Failed to write snapshot to {self._snapshot_dir}") def _load_snapshot(self): - data = self._disk_cache.get("snapshot") + try: + data = self._disk_cache.get("snapshot") + except Exception: + logger.warning(f"Failed to load snapshot from {self._snapshot_dir}, clearing it.") + self._disk_cache.clear() + return if not data: return diff --git a/core/single_object_data_cache.py b/core/single_object_data_cache.py index 66b1d7f..f4d164a 100644 --- a/core/single_object_data_cache.py +++ b/core/single_object_data_cache.py @@ -21,7 +21,13 @@ class SingleObjectDataCache: # This cache stores a single object, doesn't matter what it's called so "object" will do if "object" not in self._cache: self._cache.add("object", object_if_empty) - self._obj = self._cache.get("object") + try: + self._obj = self._cache.get("object") + except Exception: + logger.warning(f"Failed to load cache from {cache_dir}, clearing it.") + self._cache.clear() + self._cache.add("object", object_if_empty) + self._obj = object_if_empty def get(self): """Get the data object. This can then be manipulated as necessary across multiple threads. Any function diff --git a/templates/add_spot.html b/templates/add_spot.html index b629870..3d9632a 100644 --- a/templates/add_spot.html +++ b/templates/add_spot.html @@ -77,7 +77,7 @@ - + diff --git a/templates/alerts.html b/templates/alerts.html index a3b58e0..db16f4b 100644 --- a/templates/alerts.html +++ b/templates/alerts.html @@ -83,7 +83,7 @@ - + diff --git a/templates/bands.html b/templates/bands.html index dc7a4df..4c6b19d 100644 --- a/templates/bands.html +++ b/templates/bands.html @@ -76,8 +76,8 @@ - - + + diff --git a/templates/base.html b/templates/base.html index 75a8643..27c8fae 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,6 +1,6 @@ {% extends "skeleton.html" %} {% block head_extra %} - + @@ -16,10 +16,10 @@ window.fetchEventSource = fetchEventSource; - - - - + + + + {% end %} {% block body %}
diff --git a/templates/conditions.html b/templates/conditions.html index 7f5c5c4..6722749 100644 --- a/templates/conditions.html +++ b/templates/conditions.html @@ -284,7 +284,7 @@
- + diff --git a/templates/map.html b/templates/map.html index 286f01c..d956aa2 100644 --- a/templates/map.html +++ b/templates/map.html @@ -113,8 +113,8 @@ const CARTODB_API_KEY = "{{ web_ui_options.get('cartodb_api_key', '') }}"; - - + + diff --git a/templates/spots.html b/templates/spots.html index aff599b..01cf1f3 100644 --- a/templates/spots.html +++ b/templates/spots.html @@ -125,8 +125,8 @@ - - + + diff --git a/templates/status.html b/templates/status.html index 0513b7b..cff0984 100644 --- a/templates/status.html +++ b/templates/status.html @@ -96,7 +96,7 @@ - +