From 0c5e1cb5b07360b75d98884868cea81d087bdde5 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Fri, 26 May 2023 09:23:22 -0700 Subject: [PATCH] cache: scope all keys we use Signed-off-by: Varun Patil --- src/components/frame/XImgWorker.ts | 2 +- src/service-worker.js | 6 +++--- src/services/static-config.ts | 2 +- src/services/utils/cache.ts | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/frame/XImgWorker.ts b/src/components/frame/XImgWorker.ts index 73f31277..4f563278 100644 --- a/src/components/frame/XImgWorker.ts +++ b/src/components/frame/XImgWorker.ts @@ -20,7 +20,7 @@ let fetchPreviewQueue: FetchPreviewObject[] = []; const pendingUrls = new Map(); // Cache for preview images -const cacheName = 'images'; +const cacheName = 'memories-images'; let imageCache: Cache; (async function openCache() { try { diff --git a/src/service-worker.js b/src/service-worker.js index 8358cf1c..580b389a 100644 --- a/src/service-worker.js +++ b/src/service-worker.js @@ -9,7 +9,7 @@ cleanupOutdatedCaches(); registerRoute( /^.*\/apps\/memories\/api\/video\/livephoto\/.*/, new CacheFirst({ - cacheName: 'livephotos', + cacheName: 'memories-livephotos', plugins: [ new ExpirationPlugin({ maxAgeSeconds: 3600 * 24 * 7, // days @@ -30,7 +30,7 @@ const networkOnly = [/^.*\/api\/.*/]; registerRoute( ({ url }) => url.origin === self.location.origin && url.pathname.endsWith('/apps/memories/'), new NetworkFirst({ - cacheName: 'pages', + cacheName: 'memories-pages', }) ); @@ -38,7 +38,7 @@ registerRoute( registerRoute( ({ url }) => url.origin === self.location.origin && !networkOnly.some((regex) => regex.test(url.href)), new CacheFirst({ - cacheName: 'pages', + cacheName: 'memories-pages', plugins: [ new ExpirationPlugin({ maxAgeSeconds: 3600 * 24 * 7, // days diff --git a/src/services/static-config.ts b/src/services/static-config.ts index 98e74503..ecefdfd8 100644 --- a/src/services/static-config.ts +++ b/src/services/static-config.ts @@ -44,7 +44,7 @@ class StaticConfig { } // Clear page cache, keep other caches - window.caches?.delete('pages'); + window.caches?.delete('memories-pages'); } // Assign to existing default diff --git a/src/services/utils/cache.ts b/src/services/utils/cache.ts index 533c5f03..5d4265ca 100644 --- a/src/services/utils/cache.ts +++ b/src/services/utils/cache.ts @@ -6,7 +6,7 @@ const uid = getCurrentUser()?.uid || 'guest'; async function getCacheName() { const ver = await config.get('version'); - return `memories-${ver}-${uid}`; + return `memories-data-${ver}-${uid}`; } // Clear all caches except the current one @@ -19,7 +19,7 @@ async function getCacheName() { const cacheName = await getCacheName(); for (const key of keys) { - if (key.startsWith('memories-') && key !== cacheName) { + if (key.match(/^memories-data-/) && key !== cacheName) { window.caches.delete(key); } }