July 2018
Intermediate to advanced
354 pages
8h 51m
English
Like the maxItems strategy, the updateStaleEntries strategy opens a reference to the named cache and gets a list of the cached requests. This time, individual requests must be retrieved from the cache.
This requires calling the cache's match method by passing a request object (key). This will return the stored response with a date header. This is added when the item is added to the cache and can be used to determine if the response is stale:
updateStaleEntries(rule) {
self.caches.open(rule.cacheName)
.then(cache => {
cache.keys().then(keys => {
keys.forEach((request, index, array) => {
cache.match(request).then(response => {
let date = new Date(response.headers.get("date")), current = new Date(Date.now()); ...Read now
Unlock full access