0

I am caching some data using indexedDb and HTML/CSS files using service-worker.As the offline feature that is developed is going to Production, I want to know whether there is any expiration time or any limit when the cached files will be cleared if the system is not connected to online at all.

By default service workers expires after 24 hours. I already have an idea about how the service-worker is updated for each change and for each deployment.

Just to reiterate the question is, Is there any time limit when the cached files will be automatically cleared, if the system is not connected to online till a particular period

  • Are you using the *cache* API? Then it should persist: https://w3c.github.io/ServiceWorker/#cache-lifetimes For indexeddb see this [Q/A](https://stackoverflow.com/questions/15816784/persistence-lifetime), but basically, except if running out of space or if the users themselves do clear it, you should be fine. – Kaiido Aug 29 '19 at 05:09
  • That was not an answer but a request for more information about your situation. – Kaiido Aug 29 '19 at 08:33

1 Answers1

0

By default service workers expires after 24 hours...

This is not the case. Service workers don't "expire" after any length of time. After you've registered a service worker, there will be an automatic, browser-initiated check for updates to the service worker's URL each time there's a navigation request, or each time some other event wakes up the service worker (like sync or push). There's more information at https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#updates

To answer your original question, though, there is no automatic time-to-live or expiration policy that applies to either the Cache Storage API or IndexedDB. It's your responsibility to clean up old or no longer needed entries. (Or you could use libraries like workbox-expiration to help.)

Jeff Posnick
  • 53,580
  • 14
  • 141
  • 167