Skip to content

Instantly share code, notes, and snippets.

@arunrreddy
Created September 16, 2024 05:07
Show Gist options
  • Select an option

  • Save arunrreddy/5e2880d6d6515a1b1364e01bf3f3e71c to your computer and use it in GitHub Desktop.

Select an option

Save arunrreddy/5e2880d6d6515a1b1364e01bf3f3e71c to your computer and use it in GitHub Desktop.
Clear Cache based on local storage key
function async deleteCaches() {
try {
const keys = await window.caches.keys();
await Promise.all(keys.map(key => caches.delete(key)));
} catch (err) {
console.log('deleteCache err: ', err);
}
}
// run this function on your app load
function resetCacheForUpdate() {
if (!localStorage.getItem('cacheReset')) {
deleteCaches()
.then(_ => {
localStorage.setItem('cacheReset', 'yes');
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment