How DiskLruCache works
masterDiskLruCache is a filesystem-based cache that uses a bounded amount of space. It stores entries consisting of a string key and a fixed number of byte-sequence values.
Key Constraints
- Key Format: Keys must match the regex
[a-z0-9_-]{1,64}. - Value Size: Each value must be between
0andInteger.MAX_VALUEbytes. - Directory Exclusivity: The directory used by the cache must be exclusive to that cache instance. Multiple processes must not use the same directory simultaneously, as the cache may delete or overwrite files.
- Space Management: The cache enforces a byte limit. When exceeded, it removes entries in the background. Note that the limit is not strict (it may temporarily exceed the limit during deletion) and does not include filesystem overhead or the cache journal. It is recommended to set a conservative limit for space-sensitive applications.
Error Handling
- The implementation is tolerant of some I/O errors: if files are missing, entries are dropped.
- If a write error occurs during an edit, the edit fails silently.
- For other issues, callers must catch
IOException.