Skip to content

Commit

Permalink
Investigate SW cache keys
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeaun committed Sep 17, 2024
1 parent f59058e commit efb42ca
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/locales/en.po

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions src/pages/settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -841,13 +841,71 @@ function Settings({ onClose }) {
)}
</ul>
)}
<p>Service Worker Cache</p>
<button
type="button"
class="plain2 small"
onClick={async () => alert(await getCachesKeys())}
>
Show keys count
</button>{' '}
<button
type="button"
class="plain2 small"
onClick={() => {
const key = prompt('Enter cache key');
if (!key) return;
try {
clearCacheKey(key);
} catch (e) {
alert(e);
}
}}
>
Clear cache key
</button>{' '}
<button
type="button"
class="plain2 small"
onClick={() => {
try {
clearCaches();
} catch (e) {
alert(e);
}
}}
>
Clear all caches
</button>
</details>
)}
</main>
</div>
);
}

async function getCachesKeys() {
const keys = await caches.keys();
const total = {};
for (const key of keys) {
const cache = await caches.open(key);
const k = await cache.keys();
total[key] = k.length;
}
return total;
}

function clearCacheKey(key) {
return caches.delete(key);
}

async function clearCaches() {
const keys = await caches.keys();
for (const key of keys) {
await caches.delete(key);
}
}

function PushNotificationsSection({ onClose }) {
if (!isPushSupported()) return null;

Expand Down

0 comments on commit efb42ca

Please sign in to comment.