this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Make sure cleanup runs at least once

+25 -17
+25 -17
src/main.jsx
··· 50 50 51 51 // Service worker cache cleanup 52 52 if ('serviceWorker' in navigator && typeof caches !== 'undefined') { 53 - const MAX_SW_CACHE_SIZE = 30; 53 + const MAX_SW_CACHE_SIZE = 50; 54 54 const IGNORE_CACHE_KEYS = ['icons']; 55 - const clearCaches = async () => { 56 - if (!window.__IDLE__) return; 57 - const keys = await caches.keys(); 58 - for (const key of keys) { 59 - if (IGNORE_CACHE_KEYS.includes(key)) continue; 60 - const cache = await caches.open(key); 61 - const _keys = await cache.keys(); 62 - if (_keys.length > MAX_SW_CACHE_SIZE) { 63 - console.warn('Cleaning cache', key, _keys.length); 64 - const deleteKeys = _keys.slice(MAX_SW_CACHE_SIZE); 65 - for (const deleteKey of deleteKeys) { 66 - await cache.delete(deleteKey); 55 + let clearedOnce = false; 56 + const FAST_INTERVAL = 10_000; // 10 seconds 57 + const SLOW_INTERVAL = 60 * 60 * 1000; // 1 hour 58 + async function clearCaches() { 59 + if (window.__IDLE__) { 60 + try { 61 + const keys = await caches.keys(); 62 + for (const key of keys) { 63 + if (IGNORE_CACHE_KEYS.includes(key)) continue; 64 + const cache = await caches.open(key); 65 + const _keys = await cache.keys(); 66 + if (_keys.length > MAX_SW_CACHE_SIZE) { 67 + console.warn('Cleaning cache', key, _keys.length); 68 + const deleteKeys = _keys.slice(MAX_SW_CACHE_SIZE); 69 + for (const deleteKey of deleteKeys) { 70 + await cache.delete(deleteKey); 71 + } 72 + clearedOnce = true; 73 + } 67 74 } 68 - } 75 + } catch (e) {} // Silent fail 69 76 } 70 - }; 71 - setTimeout(clearCaches, 10_000); // after 10 seconds 72 - setInterval(clearCaches, 30 * 60 * 1000); // every 30 minutes 77 + // Once cleared, clear again at slower interval 78 + setTimeout(clearCaches, clearedOnce ? SLOW_INTERVAL : FAST_INTERVAL); 79 + } 80 + setTimeout(clearCaches, FAST_INTERVAL); 73 81 } 74 82 75 83 window.__CLOAK__ = () => {