fix(01-06): purge owned PWA caches on session end

- delete current and legacy HealthLog static page and data caches
- preserve unrelated CacheStorage namespaces during activation and logout
- keep IndexedDB query-cache removal in the session-end boundary
This commit is contained in:
Marc-André Bombeck committed 2026-07-29 13:46:15 +02:00
1 parent 31248ec273
commit 338dbe6c1f
2 files changed
+17 -6

No files matched your search

+5 -5
View File
@@ -39,6 +39,10 @@ const STORE = "kv";
const KEY = "react-query";
const VERSION_KEY = "react-query-version";
const MAX_AGE_MS = 24 * 60 * 60 * 1000; // discard anything older than a day
// Keep this ownership contract aligned with `public/sw.js`. Session-end
// cleanup removes every current/legacy HealthLog cache family while leaving
// unrelated CacheStorage namespaces on the same origin untouched.
const HEALTHLOG_CACHE_NAME_RE = /^healthlog-(?:static|pages|data)-/;
/**
* Upper bound on the serialized snapshot. The allowlist already caps WHAT is
@@ -326,11 +330,7 @@ export async function clearOfflineCachesForSessionEnd(): Promise<void> {
const keys = await caches.keys();
await Promise.all(
keys
.filter(
(k) =>
k.startsWith("healthlog-data-") ||
k.startsWith("healthlog-pages-"),
)
.filter((k) => HEALTHLOG_CACHE_NAME_RE.test(k))
.map((k) => caches.delete(k)),
);
} catch {