Search code examples
cachingquotaservice-worker

How can I get the size and/or number of elements in a ServiceWorker cache?


ServiceWorker is a new api available in Chrome. One of the many things it lets you do is intercept network requests and respond with a cached version. I'm implementing a "take this offline" button which dynamically adds things to the cache. I'd like to report to the user how much space I'm using, and how many entries I've put in the cache.

Is it possible to query a cache to get the number of items in it? Can I report the total size of things cached in it?


Solution

  • Apparently you can use cacheName.keys().length as shown in trained to thrill, you can also cycle on the single entries and compute the total weight.