'Workbox ExpirationPlugin delete custom IndexedDB data
For each cache I am setting corresponding data to the cache into the IndexedDB. Is it possible to delete this data too when the ExpirationPlugin deletes the cache?
Solution 1:[1]
The deleteCacheAndMetadata()
method of an ExpirationPlugin
instance sounds like what you're looking for.
Here's an explanation from the docs:
This is a helper method that performs two operations:
- Deletes all the underlying Cache instances associated with this plugin instance, by calling
caches.delete()
on your behalf.- Deletes the metadata from IndexedDB used to keep track of expiration details for each Cache instance.
When using cache expiration, calling this method is preferable to calling
caches.delete()
directly, since this will ensure that the IndexedDB metadata is also cleanly removed and open IndexedDB instances are deleted.Note that if you're not using cache expiration for a given cache, calling
caches.delete()
and passing in the cache's name should be sufficient. There is no Workbox-specific method needed for cleanup in that case.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jeff Posnick |