Closed Bug 1629202 Opened 6 years ago Closed 6 years ago

Storage estimate does not return the correct cache storage usage

Categories

(Core :: Storage: Cache API, defect)

75 Branch
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: zeroliu, Unassigned)

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36

Steps to reproduce:

  1. Check the current storage usage with navigator.storage.estimate()
  2. Add a sized string to cache.
    const str = new Array(1024*1024/4+1).join('abcd');
    const response = new Response(str);
    const cache = await caches.open('test');
    cache.put('foo', response);
  3. Check storage usage again

Actual results:

Usage increased by 164795 bytes

Expected results:

Usage should increase by 1MB. Chrome works as expected.

Version: 74 Branch → 75 Branch

UA: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:75.0) Gecko/20100101 Firefox/75.0

Flags: needinfo?(ttung)

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → Storage: Quota Manager
Product: Firefox → Core

This is most likely because cache API in firefox compresses body data.

(In reply to Xiyuan Liu from comment #0)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36

Steps to reproduce:

  1. Check the current storage usage with navigator.storage.estimate()
  2. Add a sized string to cache.
    const str = new Array(1024*1024/4+1).join('abcd');
    const response = new Response(str);
    const cache = await caches.open('test');
    cache.put('foo', response);
  3. Check storage usage again

Actual results:

Usage increased by 164795 bytes

Expected results:

Usage should increase by 1MB. Chrome works as expected.

It's not clear to me why you expect Cache API should store 1 MB in this case. My understanding is that browsers can have their own implementations unless the spec specifies the behavior.

And, I think Ben's comment in comment 3 is correct. It's because Cache API compresses body data.

Please feel free to reopen this if you don't think so.

Status: UNCONFIRMED → RESOLVED
Closed: 6 years ago
Component: Storage: Quota Manager → Storage: Cache API
Flags: needinfo?(ttung)
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.