Investigate SW cache keys

This commit is contained in:
Lim Chee Aun 2024-09-17 17:17:43 +08:00
parent f59058efa1
commit efb42ca911
2 changed files with 77 additions and 19 deletions

38
src/locales/en.po generated
View file

@ -194,7 +194,7 @@ msgstr ""
#: src/pages/catchup.jsx:72
#: src/pages/catchup.jsx:1447
#: src/pages/catchup.jsx:2068
#: src/pages/settings.jsx:1045
#: src/pages/settings.jsx:1103
msgid "Boosts"
msgstr ""
@ -1251,7 +1251,7 @@ msgstr ""
#: src/pages/home.jsx:224
#: src/pages/mentions.jsx:20
#: src/pages/mentions.jsx:167
#: src/pages/settings.jsx:1037
#: src/pages/settings.jsx:1095
#: src/pages/trending.jsx:381
msgid "Mentions"
msgstr ""
@ -1306,7 +1306,7 @@ msgstr ""
#: src/pages/catchup.jsx:2062
#: src/pages/favourites.jsx:11
#: src/pages/favourites.jsx:23
#: src/pages/settings.jsx:1041
#: src/pages/settings.jsx:1099
msgid "Likes"
msgstr ""
@ -2298,7 +2298,7 @@ msgid "<0/> <1/> boosted"
msgstr ""
#: src/components/timeline.jsx:453
#: src/pages/settings.jsx:1065
#: src/pages/settings.jsx:1123
msgid "New posts"
msgstr ""
@ -3137,7 +3137,7 @@ msgid "{0, plural, one {Announcement} other {Announcements}}"
msgstr ""
#: src/pages/notifications.jsx:599
#: src/pages/settings.jsx:1053
#: src/pages/settings.jsx:1111
msgid "Follow requests"
msgstr ""
@ -3492,56 +3492,56 @@ msgstr ""
msgid "Unable to copy version string"
msgstr ""
#: src/pages/settings.jsx:950
#: src/pages/settings.jsx:955
#: src/pages/settings.jsx:1008
#: src/pages/settings.jsx:1013
msgid "Failed to update subscription. Please try again."
msgstr ""
#: src/pages/settings.jsx:961
#: src/pages/settings.jsx:1019
msgid "Failed to remove subscription. Please try again."
msgstr ""
#: src/pages/settings.jsx:968
#: src/pages/settings.jsx:1026
msgid "Push Notifications (beta)"
msgstr ""
#: src/pages/settings.jsx:990
#: src/pages/settings.jsx:1048
msgid "Push notifications are blocked. Please enable them in your browser settings."
msgstr ""
#: src/pages/settings.jsx:999
#: src/pages/settings.jsx:1057
msgid "Allow from <0>{0}</0>"
msgstr ""
#: src/pages/settings.jsx:1008
#: src/pages/settings.jsx:1066
msgid "anyone"
msgstr ""
#: src/pages/settings.jsx:1012
#: src/pages/settings.jsx:1070
msgid "people I follow"
msgstr ""
#: src/pages/settings.jsx:1016
#: src/pages/settings.jsx:1074
msgid "followers"
msgstr ""
#: src/pages/settings.jsx:1049
#: src/pages/settings.jsx:1107
msgid "Follows"
msgstr ""
#: src/pages/settings.jsx:1057
#: src/pages/settings.jsx:1115
msgid "Polls"
msgstr ""
#: src/pages/settings.jsx:1061
#: src/pages/settings.jsx:1119
msgid "Post edits"
msgstr ""
#: src/pages/settings.jsx:1082
#: src/pages/settings.jsx:1140
msgid "Push permission was not granted since your last login. You'll need to <0><1>log in</1> again to grant push permission</0>."
msgstr ""
#: src/pages/settings.jsx:1098
#: src/pages/settings.jsx:1156
msgid "NOTE: Push notifications only work for <0>one account</0>."
msgstr ""

View file

@ -841,6 +841,42 @@ 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>
@ -848,6 +884,28 @@ function Settings({ onClose }) {
);
}
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;