0

I need all of the users of my application(desktop and tablet users) to start everyday with an empty cache. Is there any way I can take advantage of service workers to achieve this? Has anybody ever tried to do this? Or do you think there's a better way to run a schedule tasked on all the devices where my PWA is installed.

Thanks

eddy
  • 4,373
  • 16
  • 60
  • 94
  • do you have `ngsw-config.json`? – demkovych Jan 31 '20 at 15:22
  • Check [maxAge](https://github.com/angular/angular/blob/b78ada198add37827fd56c284ce6ab8fc4988180/aio/content/guide/service-worker-configref.md#maxage) param here. – demkovych Jan 31 '20 at 15:25
  • No, I have a simple sw file – eddy Jan 31 '20 at 15:25
  • then you need to manipulate with server headers. `Cache-Control: max-age=xxx` – demkovych Jan 31 '20 at 15:28
  • But that cache configuration, will work for everything in the localStorage, sessionStorage and IndexedDb ? – eddy Jan 31 '20 at 16:04
  • What I need is something similar to a scheduled task where I can clear the storage, – eddy Jan 31 '20 at 16:07
  • [here is a good explanation](https://phyks.me/2019/01/manage-expiration-of-cached-assets-with-service-worker-caching.html) – demkovych Jan 31 '20 at 16:10
  • From the docs : "...a Cache interface, that lets you **create stores of responses keyed by request** " The responses of my request are saved to IndexedDb. Sorry, but I failed to see how can I apply the content of that article to this particular case – eddy Jan 31 '20 at 16:31

1 Answers1

0

Service worker cache super-cedes browser cache and honestly you should focus more on it than browser cache. There is not a way to purge browser cache via the service worker or UI script for that matter. You have no control over that.

Even setting the Cache-Control header may not really matter. Browsers can be more aggressive as they deem necessary. Routers, load balancers, etc call get in the way as well.

If you are using service worker cache you can invalidate it any way you want. I have made some very sophisticated service workers, especially in recent months around invalidating cached assets in SW cache and indexedDB.

It is way more complex than I can share here LOL. There are numerous strategies you can employ, it all depends on what goals you have and what call the persona of your network addressable assets :)

Chris Love
  • 3,740
  • 1
  • 19
  • 16