July 2018
Intermediate to advanced
354 pages
8h 51m
English
The maxItems strategy limits how many items can be stored in a named cache. It works by opening the named cache, and then retrieving an array of requests using the keys method.
The routine then compares the number of stored items (keys.length) to the maximum number of items allowed in this cache. If there are more items than the quota, the number of items exceeding the quota is calculated.
A for loop is then executed to delete the first item from the cache and repeats until the number of items to purge have been deleted:
maxItems(options) {
self.caches.open(options.cacheName)
.then(cache => {
cache.keys().then(keys => {
if (keys.length > options.strategyOptions.max) {
let purge = keys.length - options.strategyOptions.max; ...Read now
Unlock full access