Back to Fresco

DiskStorageCache

docs/javadoc/reference/com/facebook/cache/disk/DiskStorageCache.html

3.6.023.3 KB
Original Source

Fresco

|

|

Packages | Classes

Interfaces

Classes

Annotations

Packages | Classes

Summary: Nested Classes | Constants | Ctors | Methods | Protected Methods | Inherited Methods | [Expand All]

public class

DiskStorageCache

extends Object
implements FileCacheDiskTrimmable

| java.lang.Object | | ↳ | com.facebook.cache.disk.DiskStorageCache |

Class Overview

Cache that manages disk storage.

Summary

Nested Classes
class
Constants
int
Public Constructors
Public Methods
void
long
Deletes old cache files.
long
DiskStorage.DiskDumpInfo
BinaryResource
Retrieves the file corresponding to the mKey, if it is in the cache.
long
boolean
boolean
Returns true if the key is in the in-memory key index.
BinaryResource
Inserts resource into file with key
boolean
Tells if this cache is enabled.
boolean
Tells if memory index is completed in initialization.
boolean
Probes whether the object corresponding to the mKey is in the cache.
void
Removes a resource by key from cache.
void
Called when there is very little disk space left.
void
Called when there is almost no disk space left and the app is likely to crash soon
Protected Methods
void
Blocks current thread until having finished initialization in Memory Index.

| [Expand] Inherited Methods | | --- | | From class java.lang.Object

| Object | clone() | | boolean | equals(Object arg0) | | void | finalize() | | final Class<?> | getClass() | | int | hashCode() | | final void | notify() | | final void | notifyAll() | | String | toString() | | final void | wait(long arg0, int arg1) | | final void | wait(long arg0) | | final void | wait() |

| | From interface com.facebook.cache.disk.FileCache

| abstract void | clearAll() | | abstract long | clearOldEntries(long cacheExpirationMs) Deletes old cache files. | | abstract long | getCount() | | abstract DiskStorage.DiskDumpInfo | getDumpInfo() | | abstract BinaryResource | getResource(CacheKey key) Returns the binary resource cached with key. | | abstract long | getSize() | | abstract boolean | hasKey(CacheKey key) | | abstract boolean | hasKeySync(CacheKey key) Returns true if the key is in the in-memory key index. | | abstract BinaryResource | insert(CacheKey key, WriterCallback writer) Inserts resource into file with key | | abstract boolean | isEnabled() Tells if this cache is enabled. | | abstract boolean | probe(CacheKey key) | | abstract void | remove(CacheKey key) Removes a resource by key from cache. |

| | From interface com.facebook.common.disk.DiskTrimmable

| abstract void | trimToMinimum() Called when there is very little disk space left. | | abstract void | trimToNothing() Called when there is almost no disk space left and the app is likely to crash soon |

|

Constants

public static final int START_OF_VERSIONING

Constant Value: 1 (0x00000001)

Public Constructors

public DiskStorageCache(DiskStorage diskStorage, EntryEvictionComparatorSupplier entryEvictionComparatorSupplier, DiskStorageCache.Params params, CacheEventListener cacheEventListener, CacheErrorLogger cacheErrorLogger, DiskTrimmableRegistry diskTrimmableRegistry, Executor executorForBackgrountInit, boolean indexPopulateAtStartupEnabled)

Public Methods

public void clearAll()

public long clearOldEntries(long cacheExpirationMs)

Deletes old cache files.

Parameters

| cacheExpirationMs | files older than this will be deleted. |

Returns
  • the age in ms of the oldest file remaining in the cache.

public long getCount()

public DiskStorage.DiskDumpInfo getDumpInfo()

Throws

| IOException | |

public 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 |

Returns
  • The resource if present in cache, otherwise null

public long getSize()

public boolean hasKey(CacheKey key)

public 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.

public BinaryResource insert(CacheKey key, WriterCallback callback)

Inserts resource into file with key

Parameters

| key | cache key | | callback | Callback that writes to an output stream |

Returns
  • a sequence of bytes
Throws

| IOException | |

public boolean isEnabled()

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.

Returns
  • true if this cache is usable, false otherwise.

public boolean isIndexReady()

Tells if memory index is completed in initialization. Only call it when you need to know if memory index is completed in cold start.

public boolean probe(CacheKey key)

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.

Parameters

| key | the mKey to check |

Returns
  • whether the keyed mValue is in the cache

public void remove(CacheKey key)

Removes a resource by key from cache.

Parameters

| key | cache key |

public void trimToMinimum()

Called when there is very little disk space left.

public void trimToNothing()

Called when there is almost no disk space left and the app is likely to crash soon

Protected Methods

protected void awaitIndex()

Blocks current thread until having finished initialization in Memory Index. Call only when you need memory index in cold start.

+Generated by Doclava. +