mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-12-18 08:32:33 +03:00
Double-down on reducing cache size
This commit is contained in:
parent
15732dc466
commit
73a4326b55
1 changed files with 18 additions and 18 deletions
36
src/main.jsx
36
src/main.jsx
|
@ -50,26 +50,26 @@ setTimeout(() => {
|
||||||
|
|
||||||
// Service worker cache cleanup
|
// Service worker cache cleanup
|
||||||
if ('serviceWorker' in navigator && typeof caches !== 'undefined') {
|
if ('serviceWorker' in navigator && typeof caches !== 'undefined') {
|
||||||
const MAX_SW_CACHE_SIZE = 300;
|
const MAX_SW_CACHE_SIZE = 30;
|
||||||
let swInterval = setInterval(() => {
|
const IGNORE_CACHE_KEYS = ['icons'];
|
||||||
if (window.__IDLE__) {
|
const clearCaches = async () => {
|
||||||
clearInterval(swInterval);
|
if (!window.__IDLE__) return;
|
||||||
(async () => {
|
const keys = await caches.keys();
|
||||||
const keys = await caches.keys();
|
for (const key of keys) {
|
||||||
for (const key of keys) {
|
if (IGNORE_CACHE_KEYS.includes(key)) continue;
|
||||||
const cache = await caches.open(key);
|
const cache = await caches.open(key);
|
||||||
const _keys = await cache.keys();
|
const _keys = await cache.keys();
|
||||||
if (_keys.length > MAX_SW_CACHE_SIZE) {
|
if (_keys.length > MAX_SW_CACHE_SIZE) {
|
||||||
console.warn('Cleaning cache', key, _keys.length);
|
console.warn('Cleaning cache', key, _keys.length);
|
||||||
const deleteKeys = _keys.slice(MAX_SW_CACHE_SIZE);
|
const deleteKeys = _keys.slice(MAX_SW_CACHE_SIZE);
|
||||||
for (const deleteKey of deleteKeys) {
|
for (const deleteKey of deleteKeys) {
|
||||||
await cache.delete(deleteKey);
|
await cache.delete(deleteKey);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})();
|
}
|
||||||
}
|
}
|
||||||
}, 15_000);
|
};
|
||||||
|
setTimeout(clearCaches, 10_000); // after 10 seconds
|
||||||
|
setInterval(clearCaches, 30 * 60 * 1000); // every 30 minutes
|
||||||
}
|
}
|
||||||
|
|
||||||
window.__CLOAK__ = () => {
|
window.__CLOAK__ = () => {
|
||||||
|
|
Loading…
Reference in a new issue