Skip to content

Commit

Permalink
Fix wrong "once" logic 🤦‍♂️
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeaun committed Sep 18, 2024
1 parent 0e3cc86 commit 905295a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ setTimeout(() => {
if ('serviceWorker' in navigator && typeof caches !== 'undefined') {
const MAX_SW_CACHE_SIZE = 50;
const IGNORE_CACHE_KEYS = ['icons'];
let clearedOnce = false;
let clearRanOnce = false;
const FAST_INTERVAL = 10_000; // 10 seconds
const SLOW_INTERVAL = 60 * 60 * 1000; // 1 hour
async function clearCaches() {
Expand All @@ -69,13 +69,13 @@ if ('serviceWorker' in navigator && typeof caches !== 'undefined') {
for (const deleteKey of deleteKeys) {
await cache.delete(deleteKey);
}
clearedOnce = true;
}
}
clearRanOnce = true;
} catch (e) {} // Silent fail
}
// Once cleared, clear again at slower interval
setTimeout(clearCaches, clearedOnce ? SLOW_INTERVAL : FAST_INTERVAL);
setTimeout(clearCaches, clearRanOnce ? SLOW_INTERVAL : FAST_INTERVAL);
}
setTimeout(clearCaches, FAST_INTERVAL);
}
Expand Down

0 comments on commit 905295a

Please sign in to comment.