public class

BufferedDiskCache

extends Object
java.lang.Object
   ↳ com.facebook.imagepipeline.cache.BufferedDiskCache

Class Overview

BufferedDiskCache provides get and put operations to take care of scheduling disk-cache read/writes.

Summary

Public Constructors
BufferedDiskCache(FileCache fileCache, PooledByteBufferFactory pooledByteBufferFactory, PooledByteStreams pooledByteStreams, Executor readExecutor, Executor writeExecutor, ImageCacheStatsTracker imageCacheStatsTracker)
Public Methods
void addKeyForAsyncProbing(CacheKey key)
Task<Void> clearAll()
Clears the disk cache and the staging area.
Task<Boolean> contains(CacheKey key)
Performs a key-value look up in the disk cache.
boolean containsSync(CacheKey key)
Returns true if the key is in the in-memory key index.
boolean diskCheckSync(CacheKey key)
Performs disk cache check synchronously.
Task<EncodedImage> get(CacheKey key, AtomicBoolean isCancelled)
Performs key-value look up in disk cache.
long getSize()
Task<Void> probe(CacheKey key)
Performs key-value look up in disk cache.
void put(CacheKey key, EncodedImage encodedImage)
Associates encodedImage with given key in disk cache.
Task<Void> remove(CacheKey key)
Removes the item from the disk cache and the staging area.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public BufferedDiskCache (FileCache fileCache, PooledByteBufferFactory pooledByteBufferFactory, PooledByteStreams pooledByteStreams, Executor readExecutor, Executor writeExecutor, ImageCacheStatsTracker imageCacheStatsTracker)

Public Methods

public void addKeyForAsyncProbing (CacheKey key)

public Task<Void> clearAll ()

Clears the disk cache and the staging area.

public Task<Boolean> contains (CacheKey key)

Performs a key-value look up in the disk cache. If no value is found in the staging area, then disk cache checks are scheduled on a background thread. Any error manifests itself as a cache miss, i.e. the returned Task resolves to false.

Returns
  • Task that resolves to true if an element is found, or false otherwise

public boolean containsSync (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 boolean diskCheckSync (CacheKey key)

Performs disk cache check synchronously.

Returns
  • true if the key is found in disk cache else false

public Task<EncodedImage> get (CacheKey key, AtomicBoolean isCancelled)

Performs key-value look up in disk cache. If value is not found in disk cache staging area then disk cache read is scheduled on background thread. Any error manifests itself as cache miss, i.e. the returned task resolves to null.

Returns
  • Task that resolves to cached element or null if one cannot be retrieved; returned task never rethrows any exception

public long getSize ()

public Task<Void> probe (CacheKey key)

Performs key-value look up in disk cache. If value is not found in disk cache staging area then disk cache probing is scheduled on background thread.

public void put (CacheKey key, EncodedImage encodedImage)

Associates encodedImage with given key in disk cache. Disk write is performed on background thread, so the caller of this method is not blocked

public Task<Void> remove (CacheKey key)

Removes the item from the disk cache and the staging area.