mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 12:27:07 +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);
|
||||
res = await cache.match(url);
|
||||
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);
|
||||
res = await cache.match(url);
|
||||
isCached = !!res;
|
||||
|
||||
@@ -879,13 +879,15 @@ export default {
|
||||
},
|
||||
|
||||
async refresh () {
|
||||
const cache = await caches.open("dougal");
|
||||
for (const key of await cache.keys()) {
|
||||
// Match only resolved requests
|
||||
if (key instanceof Request) {
|
||||
if (key.url?.match(`/project/${this.$route.params.project}`)) {
|
||||
console.log("removing", key.method, key.url);
|
||||
cache.delete(key);
|
||||
if (window.caches) {
|
||||
const cache = await caches.open("dougal");
|
||||
for (const key of await cache.keys()) {
|
||||
// Match only resolved requests
|
||||
if (key instanceof Request) {
|
||||
if (key.url?.match(`/project/${this.$route.params.project}`)) {
|
||||
console.log("removing", key.method, key.url);
|
||||
cache.delete(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user