-
- All Implemented Interfaces:
-
com.facebook.cache.disk.FileCache,com.facebook.common.disk.DiskTrimmable
@ThreadSafe() public class DiskStorageCache implements FileCache, DiskTrimmable
Cache that manages disk storage.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classDiskStorageCache.Params
-
Field Summary
Fields Modifier and Type Field Description public final static intSTART_OF_VERSIONING
-
Constructor Summary
Constructors Constructor Description DiskStorageCache(DiskStorage diskStorage, EntryEvictionComparatorSupplier entryEvictionComparatorSupplier, DiskStorageCache.Params params, CacheEventListener cacheEventListener, CacheErrorLogger cacheErrorLogger, DiskTrimmableRegistry diskTrimmableRegistry, Executor executorForBackgrountInit, boolean indexPopulateAtStartupEnabled)
-
Method Summary
Modifier and Type Method Description DiskStorage.DiskDumpInfogetDumpInfo()booleanisEnabled()Tells if this cache is enabled. booleanisIndexReady()Tells if memory index is completed in initialization. BinaryResourcegetResource(CacheKey key)Retrieves the file corresponding to the mKey, if it is in the cache. booleanprobe(CacheKey key)Probes whether the object corresponding to the mKey is in the cache. BinaryResourceinsert(CacheKey key, WriterCallback callback)Inserts resource into file with key voidremove(CacheKey key)Removes a resource by key from cache. longclearOldEntries(long cacheExpirationMs)Deletes old cache files. longgetSize()longgetCount()voidclearAll()booleanhasKeySync(CacheKey key)Returns true if the key is in the in-memory key index. booleanhasKey(CacheKey key)voidtrimToMinimum()voidtrimToNothing()-
Methods inherited from class com.facebook.cache.disk.FileCache
getResource, hasKey, insert, probe -
Methods inherited from class com.facebook.common.disk.DiskTrimmable
trimToMinimum, trimToNothing -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
DiskStorageCache
DiskStorageCache(DiskStorage diskStorage, EntryEvictionComparatorSupplier entryEvictionComparatorSupplier, DiskStorageCache.Params params, CacheEventListener cacheEventListener, CacheErrorLogger cacheErrorLogger, DiskTrimmableRegistry diskTrimmableRegistry, Executor executorForBackgrountInit, boolean indexPopulateAtStartupEnabled)
-
-
Method Detail
-
getDumpInfo
DiskStorage.DiskDumpInfo getDumpInfo()
-
isEnabled
boolean isEnabled()
Tells if this cache is enabled. It's important for some caches that can be disabled withoutfurther notice (like in removable/unmountable storage). Anyway a disabled cache should justignore calls, not fail.
-
isIndexReady
boolean isIndexReady()
Tells if memory index is completed in initialization. Only call it when you need to know ifmemory index is completed in cold start.
-
getResource
@Nullable() BinaryResource getResource(CacheKey key)
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.
- Parameters:
key- the mKey to check
-
probe
boolean probe(CacheKey key)
Probes whether the object corresponding to the mKey is in the cache. Note that the act ofprobing 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 andshould NOT be called on the UI thread.
- Parameters:
key- the mKey to check
-
insert
BinaryResource insert(CacheKey key, WriterCallback callback)
Inserts resource into file with key
- Parameters:
key- cache key
-
clearOldEntries
long clearOldEntries(long cacheExpirationMs)
Deletes old cache files.
- Parameters:
cacheExpirationMs- files older than this will be deleted.
-
getSize
long getSize()
-
getCount
long getCount()
-
clearAll
void clearAll()
-
hasKeySync
boolean hasKeySync(CacheKey key)
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.
-
trimToMinimum
void trimToMinimum()
-
trimToNothing
void trimToNothing()
-
-
-
-