Cache Storage Quota Limits Under Concurrent Write Requests
0 reputation · 06 Feb 2022, 22:36 UTC
0 reputation · 06 Feb 2022, 22:36 UTC
Determine how Chrome’s Service Worker Cache API enforces per‑origin storage limits when multiple cache.put operations run concurrently, and identify the point at which writes are dropped or evicted.
Chrome allocates Cache Storage quota dynamically based on available disk space, without a fixed maximum entry count. The algorithm for calculating the quota and deciding when to evict entries is undocumented, and concurrent writes can trigger race conditions that silently drop data.
Because the quota can shift between Chrome releases, developers cannot rely on a static limit, and it is unclear how many parallel writes can be safely issued before the quota enforcement logic intervenes.
1. What is the maximum number of simultaneous cache.put operations that Chrome accepts before silently dropping some writes?
2. Does Chrome enforce a hard quota cap or a dynamic threshold when concurrent writes exceed the per‑origin storage allowance?
3. How does Chrome’s eviction policy react to concurrent writes that push the cache over the allocated quota?
33275 reputation · 07 Feb 2022, 06:25 UTC
Chrome does not have a fixed maximum number of simultaneous cache.put operations that triggers silent data drops. Instead, the Cache API relies on the browser's underlying storage manager to enforce a dynamic quota based on the origin's total allocated disk space (shared with IndexedDB and FileSystem API). When the storage limit is reached, Chrome throws a QuotaExceededError; it does not silently drop writes.
While the API does not drop writes due to concurrency counts, the asynchronous nature of these operations can create a perceived loss of data. Because cache.put returns a promise, multiple concurrent writes to the same key create a race condition. The final state of the cache depends on which promise resolves last, not the order in which they were initiated.
Confirmed Facts:
QuotaExceededError.To prevent race conditions and ensure quota stability, follow these implementation steps:
cache.put in a try-catch block to handle QuotaExceededError gracefully, allowing the application to trigger a manual cleanup or notify the user.navigator.storage.estimate() method to check remaining quota before initiating large batch writes.Chrome employs a Least Recently Used (LRU) eviction strategy. When the global disk space becomes critically low, the browser may evict entire origins' storage to reclaim space. Concurrent writes do not accelerate this process, but they do increase the total storage footprint, potentially moving the origin closer to the threshold where the browser considers it a candidate for eviction.
To verify your current environment's limits, you can run the following in the DevTools console:
const estimate = await navigator.storage.estimate();
console.log(`Usage: ${estimate.usage / 1024 / 1024} MB`);
console.log(`Quota: ${estimate.quota / 1024 / 1024} MB`);
Missing Diagnostic Detail: Are you observing specific data loss (missing keys) or receiving QuotaExceededError exceptions during your concurrent operations?
Use comments to ask for clarification. Post a solution as an answer.
33,275 reputation · 06 Feb 2022, 23:28 UTC
To clarify the behavior during high-concurrency writes, it is important to distinguish between quota enforcement and resource exhaustion. While Chrome triggers a QuotaExceededError when the origin's storage limit is hit, a massive burst of concurrent cache.put calls can lead to different failure modes before the quota is even reached.
cache.put involves a Request/Response pair in memory, initiating hundreds of parallel writes can cause the browser tab to crash or the Service Worker to be terminated due to memory exhaustion, which may appear as "dropped" writes.For reliable verification in Chrome, use navigator.storage.estimate() immediately before and after a concurrent batch to confirm if the usage value aligns with the expected data size or if promises rejected without a quota error.