GrabNguyen Van MinhProblem & solution
Reclaiming Terabytes: Optimizing Android image caching with TLRU
Summary
Grab’s Android app cached runtime images with DiskLruCache, but its 100 MB size limit did not remove stale content while the cache remained below capacity, contributing substantially to device storage usage. The team developed Time-Aware Least Recently Used (TLRU), which combines LRU size eviction with time-based expiration using last_accessed metadata and a TTL, while a minimum cache-size threshold protects a baseline of cached images. TLRU retains the 100 MB maximum and evicts entries when current_time minus last_accessed exceeds the TTL; the implementation also supports reading existing LRU journal files by ignoring timestamp suffixes, enabling safe rollback. Configuration was tuned through experiments using cache hit ratio, with a maximum acceptable decline of three percentage points. After production rollout, P95 total app size fell approximately 50 MB, while hit ratio stayed within target and infrastructure costs did not increase.
Context
The Android app’s runtime image cache contributed substantially to its disk footprint. DiskLruCache evicted entries only when the configured maximum size was exceeded, allowing outdated promotional images, infrequently used feature images, and other stale content to remain indefinitely when the cache was below its 100 MB limit.
Approach / What changed
The team evolved the standard LRU cache into TLRU, adding TTL-based eviction based on last_accessed timestamps and a minimum cache-size threshold while retaining the 100 MB maximum and traditional LRU size eviction. They tuned the parameters through controlled experiments using cache hit ratio, preserved compatibility with existing LRU journal files, and rolled the implementation out without disrupting existing cache data.
Takeaways
TLRU considers an entry expired when current_time minus last_accessed exceeds the configured TTL, then removes expired entries during cache operations.
A minimum cache-size threshold prevents time-based eviction from clearing the cache below a baseline, while the maximum size preserves traditional least-recently-used eviction.
After rollout, P95 total app size decreased by approximately 50 MB; cache hit ratio declined by no more than 3 percentage points and infrastructure costs did not increase.
Source and freshness
- Source
- engineering.grab.com
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.