Last year we enabled the Firefox disk cache on Android and improved its sizing (see for example, bug 742560, bug 745340, and bug 751603). Now that those changes are stable – no significant changes since Firefox 15 – this seems like a good time to review how Firefox for Android uses the disk cache, and why.
The Firefox disk cache uses HTTP caching to reduce page load times by saving page resources to files, and then using the saved copies – as long as they are not stale – on subsequent page loads. On Android devices, file system access is generally slower than found in desktop environments, reducing the effectiveness of disk caching. However, network latency and bandwidth are also generally slower in mobile environments, making disk caching more likely to pay off. Our tests and telemetry suggest that disk caching reduces page load times overall, and disk caching is used by competitive mobile browsers.
(Firefox also has a memory-based cache for network resources, but it is difficult to use effectively on Android, because there is usually not enough memory available to store entries long enough for them to be re-used.)
The size of the disk cache is important, and tricky to get “right”. If the maximum size of the disk cache is too small, there isn’t enough space to effectively hold content, and stored entries may be evicted before they can be re-used. However, space on some Android devices is very limited, and we don’t want Firefox for Android to use more than its fair share.
The disk cache has an optional “smart sizing” feature, which Firefox for Android uses by default, with slight modifications. With smart sizing, the maximum size of the disk cache is set dynamically, based on the amount of space available on the device’s /data partition. On devices with a great deal of storage, the cache may use up to 200 MB; devices with much less storage may be constrained to only 10 MB of cache files.
The rules for calculating the maximum size of the cache are complicated to describe, but some examples will illustrate:
- 2.5 GB or more available -> cache uses up to 200 MB
- 1 GB available -> cache uses up to 125 MB
- 500 MB available -> cache uses up to 100 MB
- 200 MB available -> caches uses up to 40 MB
- 50 MB or less available -> cache uses up to 10 MB
In this way, Firefox for Android tries to balance the need to be a “good citizen” on the device – leaving space for other apps, media, etc – with storing enough in the cache to be effective over time.
You can see your disk cache’s maximum and actual size by going to “about:cache” in Firefox:
In this example, from a tablet with lots of available storage, the maximum cache size is 200 MB (204800 KiB), with about 80 MB actually in use.
You can also see the location of the disk cache directory in the screenshot above. Notice that disk cache files reside in the Firefox profile, on Android just like for desktop Firefox. On Android, this is surprising to some people, since Android applications have their own notion of a cache directory. There is an open bug considering the possibility of moving the Firefox for Android disk cache into the Android cache directory, but that’s not simple and may take a while to work out.
To see Android’s view of Firefox’s storage requirements, you can open the Android Settings > Applications > Firefox:
This is taken from that same tablet. The Data size of 103 MB includes our 80 MB disk cache (the remainder is for fonts, databases, and miscellaneous profile data). Notice that the Android Cache is 0.00 B — as discussed, Firefox isn’t using the Android cache at all. Want to reclaim that cache space included in the Data size shown here? Remember, the cache is there for a reason, and it’s probably helping you to browse more efficiently. But if you are sure, you can always do it within Firefox: open the menu > Settings > Privacy & Security > Clear private data, and then clear the Cache:
More questions about the Firefox disk cache on Android? Let me know — :gbrown on #mobile.