Reading from deleted cache

43 Views Asked by At

I have this module test:

var myCache = await caches.open("test"); // create a new cache
await myCache.add(new Request("/index.html")); // page was sucessfully stored
await caches.delete("test");
myCache.match("/index.html"); // I still read from deleted cache!

After the cache was deleted, I don't see it anymore in browser inspector, but I still get the Response from the .match method. I'd expect error here, please explain this unexpected behaviour.

1

There are 1 best solutions below

0
On

Seems like a confusion on MDN site where they describe CacheStorage.delete as

The delete() method of the CacheStorage interface finds the Cache object matching the cacheName, and if found, deletes the Cache object and returns a Promise that resolves to true. If no Cache object is found, it resolves to false.

If fact the object is NOT deleted. The W3C specifies that the cacheJobPromise just

Remove the relevant name to cache map.

So just the key in the map is deleted, not the object itself.