GoogleChromeLabs / sw-toolbox

[Deprecated] A collection of service worker tools for offlining runtime requests
https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-sw
Apache License 2.0
3.61k stars 331 forks source link

Cache deleted on reload page #256

Open ptiswitz opened 7 years ago

ptiswitz commented 7 years ago

Hi everyone,

I'm facing a really strange issue and i need a little help.

I'm trying to cache some urls on the fly (user action). This point works well, all my urls which have the same base url (/rest/events/...), are inserted in the cache storage.

But when the page is reload only one is still there and the other one seem to be remove during the toolbox init phase.

Does anyone have an idea to solve this issue ?

Thanks

gauntface commented 7 years ago

can you share an example project or URL that shows this behavior?

ptiswitz commented 7 years ago

Hello,

Sorry for the delay but you can see the code on this gist https://gist.github.com/ptiswitz/ef40a69eb8b3d730f7d9853c77fd6a24

There is no live example, i'm sorry :)

ptiswitz commented 7 years ago

I debug step by step the toolbox script and i found that during the active phase the renameCache function is called.

It's literally replace the "previous" cache by a new one without getting back any request stored in it.

Does it have a reason to do that ?

gauntface commented 7 years ago

the activate phase means that the previous precached resources are no longer in use and can be deleted while the newly precached assets (which is performed in the install event) will be used now.

gauntface commented 7 years ago

You might find workboxjs.org a better option to achieve what you are doing as you're using toolbox and sw-precache to precache assets and I think you would be better suited to using a specific cache for your on the fly caching which I'm not sure how you can do that in sw-toolbox.