- From: Anatolij Terentjev <notifications@github.com>
- Date: Sat, 18 Jul 2020 04:30:11 -0700
- To: w3c/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Saturday, 18 July 2020 11:30:23 UTC
I apologize if the question is incorrect, I am new in javascript.
The mapbox [()](https://github.com/mapbox/mapbox-gl-js/issues/9145) uses the following code
`function cacheOpen() {
if (window.caches && !sharedCache) {
sharedCache = window.caches.open(CACHE_NAME);
}
}
export function enforceCacheSizeLimit(limit: number) {
cacheOpen();
if (!sharedCache) return;
sharedCache
.then(cache => {
if (!cache) return;
cache.keys().then(keys => {
for (let i = 0; i < keys.length - limit; i++) {
cache.delete(keys[i]);
}
});
});
}`
I insert the line
` if (!cache) return; `
to fix my problem, but I would like to understand why this is happening.
Here `https://w3c.github.io/ServiceWorker/#cachestorage` I read
`If cacheName matches key, then:
Resolve promise with a new Cache object that represents value.
Abort these steps.`
As !sharedCache = false, then I expect that promise wil resolve with new Cash, not undefined.
Can anyone explain to me what I'm wrong about?
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1524
Received on Saturday, 18 July 2020 11:30:23 UTC