java.lang.Object | |
↳ | com.facebook.cache.disk.DiskStorageCache |
Cache that manages disk storage.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
class | DiskStorageCache.Params |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | START_OF_VERSIONING |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
DiskStorageCache(DiskStorage diskStorage, EntryEvictionComparatorSupplier entryEvictionComparatorSupplier, DiskStorageCache.Params params, CacheEventListener cacheEventListener, CacheErrorLogger cacheErrorLogger, DiskTrimmableRegistry diskTrimmableRegistry, Executor executorForBackgrountInit, boolean indexPopulateAtStartupEnabled) |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void | clearAll() | ||||||||||
long |
clearOldEntries(long cacheExpirationMs)
Deletes old cache files.
| ||||||||||
long | getCount() | ||||||||||
DiskStorage.DiskDumpInfo | getDumpInfo() | ||||||||||
BinaryResource |
getResource(CacheKey key)
Retrieves the file corresponding to the mKey, if it is in the cache.
| ||||||||||
long | getSize() | ||||||||||
boolean | hasKey(CacheKey key) | ||||||||||
boolean |
hasKeySync(CacheKey key)
Returns true if the key is in the in-memory key index.
| ||||||||||
BinaryResource |
insert(CacheKey key, WriterCallback callback)
Inserts resource into file with key
| ||||||||||
boolean |
isEnabled()
Tells if this cache is enabled.
| ||||||||||
boolean |
isIndexReady()
Tells if memory index is completed in initialization.
| ||||||||||
boolean |
probe(CacheKey key)
Probes whether the object corresponding to the mKey is in the cache.
| ||||||||||
void |
remove(CacheKey key)
Removes a resource by key from cache.
| ||||||||||
void |
trimToMinimum()
Called when there is very little disk space left.
| ||||||||||
void |
trimToNothing()
Called when there is almost no disk space left and the app is likely to crash soon
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
awaitIndex()
Blocks current thread until having finished initialization in Memory Index.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
com.facebook.cache.disk.FileCache
| |||||||||||
From interface
com.facebook.common.disk.DiskTrimmable
|
Deletes old cache files.
cacheExpirationMs | files older than this will be deleted. |
---|
Retrieves the file corresponding to the mKey, if it is in the cache. Also touches the item, thus changing its LRU timestamp. If the file is not present in the file cache, returns null.
This should NOT be called on the UI thread.
key | the mKey to check |
---|
Returns true if the key is in the in-memory key index.
Not guaranteed to be correct. The cache may yet have this key even if this returns false. But if it returns true, it definitely has it.
Avoids a disk read.
Inserts resource into file with key
key | cache key |
---|---|
callback | Callback that writes to an output stream |
IOException |
---|
Tells if this cache is enabled. It's important for some caches that can be disabled without further notice (like in removable/unmountable storage). Anyway a disabled cache should just ignore calls, not fail.
Tells if memory index is completed in initialization. Only call it when you need to know if memory index is completed in cold start.
Probes whether the object corresponding to the mKey is in the cache. Note that the act of probing touches the item (if present in cache), thus changing its LRU timestamp.
This will be faster than retrieving the object, but it still has file system accesses and should NOT be called on the UI thread.
key | the mKey to check |
---|
Called when there is very little disk space left.
Called when there is almost no disk space left and the app is likely to crash soon
Blocks current thread until having finished initialization in Memory Index. Call only when you need memory index in cold start.