Downgrade gracefully if window.caches is not available.

This should not happen in production, as the Cache API is
widely implemented as of the date of this commit, but it
will not be available if the user is not in a secure
context. That should only happen during testing.
This commit is contained in:
D. Berge
2025-08-06 10:45:05 +02:00
parent 8ef56f9946
commit be7157b62c
3 changed files with 11 additions and 9 deletions

View File

@@ -19,7 +19,7 @@ async function cachedFetch(url, init, opts = {}) {
} }
} }
if (opts?.cache) { if (opts?.cache && window.cache) {
cache = await caches.open(opts.cache.name); cache = await caches.open(opts.cache.name);
res = await cache.match(url); res = await cache.match(url);
isCached = !!res; isCached = !!res;

View File

@@ -61,7 +61,7 @@ async function api ({state, getters, commit, dispatch}, [resource, init = {}, cb
} }
} }
if (opts?.cache) { if (opts?.cache && window.caches) {
cache = await caches.open(opts.cache.name); cache = await caches.open(opts.cache.name);
res = await cache.match(url); res = await cache.match(url);
isCached = !!res; isCached = !!res;

View File

@@ -879,6 +879,7 @@ export default {
}, },
async refresh () { async refresh () {
if (window.caches) {
const cache = await caches.open("dougal"); const cache = await caches.open("dougal");
for (const key of await cache.keys()) { for (const key of await cache.keys()) {
// Match only resolved requests // Match only resolved requests
@@ -889,6 +890,7 @@ export default {
} }
} }
} }
}
await this.$root.sleep(300); await this.$root.sleep(300);
this.getSequenceData(); this.getSequenceData();
}, },