July 2018
Intermediate to advanced
354 pages
8h 51m
English
The cache object's key method returns a promise that resolves an array of requests that are stored in the cache. The method has two optional parameters, request and options. These are the same two types we have seen for the other methods.
When supplying these parameters, the keys method works much like the match and matchAll methods.
The array of keys or requests can then be used to update your cache. For example, you could loop through and delete all matches or maybe do a silent background update:
caches.open(cacheName).then(function(cache) {
cache.keys().then(function(keys) {
keys.forEach(function(request) {
fetchAndUpdateCache(cacheName, request);
});
});
})
The keys are returned in insertion order. This can come in handy if ...
Read now
Unlock full access