Skip to content

Commit c2cf45d

Browse files
author
GitHub Copilot
committed
Implement no-op cache clearing for PWA utilities
1 parent c44c6d9 commit c2cf45d

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/utils/pwaUtils.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ export async function promptPWAInstall(installEvent: any): Promise<boolean> {
4949
* Clears outdated caches for storage optimization on mobile
5050
*/
5151
export async function clearOutdatedCaches(cachePrefix = 'teachlink-cache-'): Promise<void> {
52-
if (!('caches' in window)) return;
53-
// Typically executed inside the SW, but can be manually triggered if needed from client side
52+
if (typeof globalThis === 'undefined' || !('caches' in globalThis)) return;
53+
54+
try {
55+
const cacheNames = await globalThis.caches.keys();
56+
const matchingCaches = cacheNames.filter((cacheName) => cacheName.startsWith(cachePrefix));
57+
58+
await Promise.all(matchingCaches.map((cacheName) => globalThis.caches.delete(cacheName)));
59+
logger.info('Cleared outdated caches', { cachePrefix, deletedCount: matchingCaches.length });
60+
} catch (error) {
61+
logger.error('Failed to clear outdated caches', { error, cachePrefix });
62+
}
5463
}

0 commit comments

Comments
 (0)