javascriptcachingservice-workerweb-storagecachestorage

If a web app's CacheStorage Cache has too much content, can the app crash?


There's not much to read on Caches in the spec.

I'd like to know, if I am storing LARGE amounts of data in the caches, can the web application crash? Or is the runtime memory limit of the application separate from cache storage? Will the Cache unload runtime memory and fallback on filesystem if needed? Or will the Cache try to load everything into memory (thus crash)? What does it do?

I'm looking for insight into whether or not having a TON of stuff in the cache can be a source for crashes I'm experiencing.

EDIT, found the answer, below.


Solution

  • As per the this thread on the chromium-dev Google Group, CacheStorage can have errors that crash an app when it is too full. This does not have to do with the cache size limit (it uses best effort not to evict cache content).

    From the chromium-dev thread:

    Unfortunately the Cache API has a flaw in its design. The cache.keys() method returns a list of every request in a cache. You can easily use this to exhaust memory and OOM the browser. The cache.matchAll() method has a similar problem with returning every Response.

    To avoid abuse we currently limit cache query results to 10MB:

    https://cs.chromium.org/chromium/src/content/browser/cache_storage/cache_storage_cache.cc?l=70&rcl=e09c68d80742c2c73854eb4abb54c4a0878200a9

    I believe the long term plan is to make Cache API implement async iteration once its available for webidl:

    https://github.com/heycam/webidl/issues/580

    In the meantime I'm afraid you will need to construct your queries in chrome to limit them to be less than 10MB. Sharding data across cache objects may be a possible way to do that.

    Hope that helps.

    Ben