DiskLruCache is a disk-backed key-value cache library for Android and Java environments that stores data on the filesystem within a configurable byte limit. It uses a least-recently-used (LRU) eviction policy to automatically remove old entries when the cache exceeds its allocated size, and maintains a journal file to reconstruct its in-memory state after a process restart.
The cache provides atomic write operations that first write new data to a temporary file before atomically renaming it, preventing partial or corrupted reads during concurrent access. It returns frozen snapshots of cache entries at read time, ensuring consistency even if the entry is later modified. Each entry requires a monotonically increasing version number, enabling detection of stale or concurrent modifications.
Cached byte sequences can be accessed as input streams or file references, decoupling consumption from the underlying storage format. The library enforces per-entry byte size tracking to trigger eviction during writes, using a doubly linked list to track access order.