如果 Web 应用程序的 CacheStorage 缓存内容过多,应用程序会崩溃吗?

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

Caches in the spec.

上没什么可读的

我想知道,如果我在缓存中存储大量数据,Web 应用程序会崩溃吗?还是应用程序的运行时内存限制与缓存存储分开?如果需要,缓存是否会卸载运行时内存并回退到文件系统?或者缓存会尝试将所有内容加载到内存中(因此崩溃)?它有什么作用?

我想深入了解缓存中的大量内容是否会导致我遇到的崩溃。

编辑,在下面找到答案。

根据 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 不驱逐缓存内容)。

来自 chromium-dev 线程:

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