How cache storage and expiration work
developStorage
By default, files are stored in the app's temporary directory, meaning the OS may delete them at any time. Metadata about the files is stored in a database:
- Android, iOS, macOS: Uses
sqflite. - Other platforms: Uses a plain JSON file.
The database filename is derived from the
CacheManager'skey.
Updates
The manager uses the HTTP Cache-Control header and eTag to determine if a file is still valid. When calling getSingleFile or getFileStream, the manager checks if the cached file is outdated. If it is, the manager updates the file and returns the new version via the stream.
Removal
Files are removed based on two criteria:
maxNrOfCacheObjects: When the limit is reached, files are deleted based on their last use (LRU).stalePeriod: Files that haven't been used for longer than this duration are deleted during continuous cache cleaning.