-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Best practices for cleaning up old caches #1407
Comments
We used a technique outlined in this talk: https://youtu.be/fGTUIlEM0m8?t=825 We did have to create our own, parse-able cache naming scheme. It think having something default in workbox would be better. Basically our Then on |
@zevdg Thanks for the sharing. Unfortunately, it looks workbox doesn't expose any helper function to access indexedDB. So, we have to manually code it. |
We added a I'm leaving this open as this issue deals with automatically cleaning up caches from |
There doesn't seem to be an example of how to use I don't seem to be able to make an
(missing space in error message is sic) Is there something I'm missing that implicitly ties |
Apologies that this isn't clear—you're correct that It's also worth noting that in the v4.0.0 betas, the Providing either a complete list of "known" cache names, or a way of passing in a cache name and getting back a |
FYI, Workbox v4 brings a breaking change to the precache format. (This is different from the We're proving a new method, It relies on precache naming conventions, and it's possible (if unlikely) that if a developer used a similar naming convention for their own runtime caches, it could end up deleted those runtime caches as well. For that reason, it's not enabled by default, but if you know that you've never created a runtime cache with I'm going to leave this open until Workbox v4 is finalized and folks have a chance to try it out, but hopefully |
I need some help. I am creating PWA with cakePHP. My app is working fine(PWA workbox). But I have some problems or requirements for the app. Can App cache be updated automatically on any app changes(text, |
@jeffposnick Essentially, I'm attempting to have a 'reset' button in my app, which returns everything to its initial state, much like the |
Library Affected:
workbox-sw
Browser & Platform:
all browsers
Issue or Feature Request Description:
I just recently migrated from sw-precache to workbox, and I noticed that my old cache from sw-precache was sticking around indefinitely. This would also be an issue for anyone adding or changing their cacheId/prefix or suffix. I suspect that chrome will maybe clean these up eventually, but my limited understanding of service worker caches is that for the most part, chrome expects you to clean up after yourself, so lets do that. I started by looking for an option in the webpack GenerateSW plugin to delete caches that aren't part of my workbox configuration and was surprised not to find one. No matter. I expected to have to "eject" to InjectManifest eventually anyway, so I do that and wrote the following snippet
So far so good, but there's this mysterious "temp cache" that is very sparsely documented, and deleting it may cause some problems? #1368 (comment) Maybe not, but better safe than sorry.
So we add a simple
validCacheSet.add(workbox.core.cacheNames.precache+"-temp")
. This is hacky and depends on the implementation detail of the temp cache name, but it works.Then I cache my google fonts as per the instructions at https://developers.google.com/web/tools/workbox/guides/common-recipes#google_fonts and notice that this new cache name (which is required by the workbox.expiration plugin) isn't getting added to workbox.core.cacheNames, so I keep deleting it. Now to fix that, I have to keep track of my dynamic cache names too. So now I have something like this.
So I think I'm more or less doing the right thing now, but
So I suggest 2 changes that would each independently improve the situation.
I wont bike shed the semantics, but to give a concrete example, maybe something like
With this new hypothetical
workbox.core.cacheNames.all()
function, my initial solution (modified slightly to use this new function) becomes the correct one.Of course, you could also expose even higher level options on top of these like a "deleteNonWorkboxCaches" function or option on the webpack GenerateSW plugin, but that's probably overkill unless this pattern is extremely common.
The text was updated successfully, but these errors were encountered: