From de4bb84e40fc412438d4cf6dd6ef8a354f1f2b07 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sun, 16 Oct 2022 19:17:56 -0700 Subject: [PATCH] Clear old caches --- src/services/Utils.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/services/Utils.ts b/src/services/Utils.ts index c05a4d51..80f9bfc2 100644 --- a/src/services/Utils.ts +++ b/src/services/Utils.ts @@ -170,6 +170,13 @@ let staticCache: Cache | null = null; const cacheName = `memories-${loadState('memories', 'version')}-${getCurrentUser()!.uid}`; openCache().then((cache) => { staticCache = cache }); +// Clear all caches except the current one +caches.keys().then((keys) => { + keys.filter((key) => key.startsWith('memories-') && key !== cacheName).forEach((key) => { + caches.delete(key); + }); +});; + /** Open the cache */ export async function openCache() { return await caches.open(cacheName);