Created
September 16, 2024 05:07
-
-
Save arunrreddy/5e2880d6d6515a1b1364e01bf3f3e71c to your computer and use it in GitHub Desktop.
Clear Cache based on local storage key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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