mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:57:08 +00:00
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:
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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();
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user