Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save osvaldasvalutis/25b1b7474a845bd7422bcec334477a2d to your computer and use it in GitHub Desktop.
Save osvaldasvalutis/25b1b7474a845bd7422bcec334477a2d to your computer and use it in GitHub Desktop.
const trimCache = (cacheName, maxItems) => {
caches.open(cacheName).then(cache => {
cache.keys().then(keys => {
if(keys.length > maxItems)
cache.delete(keys[0]).then(trimCache(cacheName, maxItems));
});
});
};
self.addEventListener('message', event => {
if(event.data.command == 'trimCache') {
trimCache(otherCacheName, 50);
trimCache(imagesCacheName, 25);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment