The trimCache function in Going Offline …again

function trimCache(cacheName, maxItems) {
caches.open(cacheName)
.then( cache => {
cache.keys()
.then(keys => {
if (keys.length > maxItems) {
cache.delete(keys[0])
.then(
trimCache(cacheName, maxItems)
);
window.setTimeout(doSomething(someValue), 1000);
window.setTimeout( function() {
doSomething(someValue)
}, 1000);
cache.delete(keys[0])
.then(
trimCache(cacheName, maxItems)
);
cache.delete(keys[0])
.then( function() {
trimCache(cacheName, maxItems)
});
cache.delete(keys[0])
.then( () => {
trimCache(cacheName, maxItems)
});

A web developer and author living and working in Brighton, England. Everything I post on Medium is a copy — the originals are on my own website, adactio.com

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jeremy Keith

Jeremy Keith

A web developer and author living and working in Brighton, England. Everything I post on Medium is a copy — the originals are on my own website, adactio.com

More from Medium

Ain’t no party like a third party

See how our Vets@ ERG transformed MRE meals into mouthwatering morsels in our Iron Chef contest

The Shift from Polyrepos to Monorepos: Yarn Workspace