public class

ImagePipeline

extends Object
java.lang.Object
   ↳ com.facebook.imagepipeline.core.ImagePipeline

Class Overview

The entry point for the image pipeline.

Summary

Public Constructors
ImagePipeline(ProducerSequenceFactory producerSequenceFactory, Set<RequestListener> requestListeners, Set<RequestListener2> requestListener2s, Supplier<Boolean> isPrefetchEnabledSupplier, MemoryCache<CacheKeyCloseableImage> bitmapMemoryCache, MemoryCache<CacheKeyPooledByteBuffer> encodedMemoryCache, BufferedDiskCache mainBufferedDiskCache, BufferedDiskCache smallImageBufferedDiskCache, CacheKeyFactory cacheKeyFactory, ThreadHandoffProducerQueue threadHandoffProducerQueue, Supplier<Boolean> suppressBitmapPrefetchingSupplier, Supplier<Boolean> lazyDataSource, CallerContextVerifier callerContextVerifier, ImagePipelineConfig config)
Public Methods
void clearCaches()
Clear all the caches (memory and disk)
void clearDiskCaches()
Clear disk caches
void clearMemoryCaches()
Clear the memory caches
void evictFromCache(Uri uri)
If you have supplied your own cache key factory when configuring the pipeline, this method may not work correctly.
void evictFromDiskCache(Uri uri)
If you have supplied your own cache key factory when configuring the pipeline, this method may not work correctly.
void evictFromDiskCache(ImageRequest imageRequest)
Removes all images with the specified Uri from disk cache.
void evictFromMemoryCache(Uri uri)
Removes all images with the specified Uri from memory cache.
DataSource<CloseableReference<CloseableImage>> fetchDecodedImage(ImageRequest imageRequest, Object callerContext, ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit, RequestListener requestListener)
Submits a request for execution and returns a DataSource representing the pending decoded image(s).
DataSource<CloseableReference<CloseableImage>> fetchDecodedImage(ImageRequest imageRequest, Object callerContext)
Submits a request for execution and returns a DataSource representing the pending decoded image(s).
DataSource<CloseableReference<CloseableImage>> fetchDecodedImage(ImageRequest imageRequest, Object callerContext, RequestListener requestListener)
Submits a request for execution and returns a DataSource representing the pending decoded image(s).
DataSource<CloseableReference<CloseableImage>> fetchDecodedImage(ImageRequest imageRequest, Object callerContext, ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit)
Submits a request for execution and returns a DataSource representing the pending decoded image(s).
DataSource<CloseableReference<CloseableImage>> fetchDecodedImage(ImageRequest imageRequest, Object callerContext, ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit, RequestListener requestListener, String uiComponentId)
Submits a request for execution and returns a DataSource representing the pending decoded image(s).
DataSource<CloseableReference<PooledByteBuffer>> fetchEncodedImage(ImageRequest imageRequest, Object callerContext, RequestListener requestListener)
Submits a request for execution and returns a DataSource representing the pending encoded image(s).
DataSource<CloseableReference<PooledByteBuffer>> fetchEncodedImage(ImageRequest imageRequest, Object callerContext)
Submits a request for execution and returns a DataSource representing the pending encoded image(s).
DataSource<CloseableReference<CloseableImage>> fetchImageFromBitmapCache(ImageRequest imageRequest, Object callerContext)
Submits a request for bitmap cache lookup.
String generateUniqueFutureId()
Generates unique id for RequestFuture.
MemoryCache<CacheKeyCloseableImage> getBitmapMemoryCache()
CacheKey getCacheKey(ImageRequest imageRequest, Object callerContext)
CacheKeyFactory getCacheKeyFactory()
CloseableReference<CloseableImage> getCachedImage(CacheKey cacheKey)
Returns a reference to the cached image
RequestListener getCombinedRequestListener(RequestListener listener)
ImagePipelineConfig getConfig()
Supplier<DataSource<CloseableReference<CloseableImage>>> getDataSourceSupplier(ImageRequest imageRequest, Object callerContext, ImageRequest.RequestLevel requestLevel)
Returns a DataSource supplier that will on get submit the request for execution and return a DataSource representing the pending results of the task.
Supplier<DataSource<CloseableReference<CloseableImage>>> getDataSourceSupplier(ImageRequest imageRequest, Object callerContext, ImageRequest.RequestLevel requestLevel, RequestListener requestListener)
Returns a DataSource supplier that will on get submit the request for execution and return a DataSource representing the pending results of the task.
Supplier<DataSource<CloseableReference<CloseableImage>>> getDataSourceSupplier(ImageRequest imageRequest, Object callerContext, ImageRequest.RequestLevel requestLevel, RequestListener requestListener, String uiComponentId)
Returns a DataSource supplier that will on get submit the request for execution and return a DataSource representing the pending results of the task.
Supplier<DataSource<CloseableReference<PooledByteBuffer>>> getEncodedImageDataSourceSupplier(ImageRequest imageRequest, Object callerContext)
Returns a DataSource supplier that will on get submit the request for execution and return a DataSource representing the pending results of the task.
ProducerSequenceFactory getProducerSequenceFactory()
RequestListener getRequestListenerForRequest(ImageRequest imageRequest, RequestListener requestListener)
long getUsedDiskCacheSize()
Current disk caches size
boolean hasCachedImage(CacheKey cacheKey)
boolean isInBitmapMemoryCache(ImageRequest imageRequest)
Returns whether the image is stored in the bitmap memory cache.
boolean isInBitmapMemoryCache(Uri uri)
Returns whether the image is stored in the bitmap memory cache.
DataSource<Boolean> isInDiskCache(ImageRequest imageRequest)
Returns whether the image is stored in the disk cache.
DataSource<Boolean> isInDiskCache(Uri uri)
Returns whether the image is stored in the disk cache.
boolean isInDiskCacheSync(Uri uri)
Returns whether the image is stored in the disk cache.
boolean isInDiskCacheSync(Uri uri, ImageRequest.CacheChoice cacheChoice)
Returns whether the image is stored in the disk cache.
boolean isInDiskCacheSync(ImageRequest imageRequest)
Performs disk cache check synchronously.
boolean isInEncodedMemoryCache(Uri uri)
Returns whether the image is stored in the encoded memory cache.
boolean isInEncodedMemoryCache(ImageRequest imageRequest)
Returns whether the image is stored in the encoded memory cache.
Supplier<Boolean> isLazyDataSource()
boolean isPaused()
void pause()
DataSource<Void> prefetchToBitmapCache(ImageRequest imageRequest, Object callerContext, RequestListener requestListener)
DataSource<Void> prefetchToBitmapCache(ImageRequest imageRequest, Object callerContext)
Submits a request for prefetching to the bitmap cache.
DataSource<Void> prefetchToDiskCache(ImageRequest imageRequest, Object callerContext, RequestListener requestListener)
DataSource<Void> prefetchToDiskCache(ImageRequest imageRequest, Object callerContext, Priority priority)
Submits a request for prefetching to the disk cache.
DataSource<Void> prefetchToDiskCache(ImageRequest imageRequest, Object callerContext, Priority priority, RequestListener requestListener)
DataSource<Void> prefetchToDiskCache(ImageRequest imageRequest, Object callerContext)
Submits a request for prefetching to the disk cache with a default priority.
DataSource<Void> prefetchToEncodedCache(ImageRequest imageRequest, Object callerContext)
Submits a request for prefetching to the encoded cache with a default priority.
DataSource<Void> prefetchToEncodedCache(ImageRequest imageRequest, Object callerContext, RequestListener requestListener)
DataSource<Void> prefetchToEncodedCache(ImageRequest imageRequest, Object callerContext, Priority priority)
Submits a request for prefetching to the encoded cache.
DataSource<Void> prefetchToEncodedCache(ImageRequest imageRequest, Object callerContext, Priority priority, RequestListener requestListener)
void resume()
<T> DataSource<CloseableReference<T>> submitFetchRequest(Producer<CloseableReference<T>> producerSequence, SettableProducerContext settableProducerContext, RequestListener requestListener)
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ImagePipeline (ProducerSequenceFactory producerSequenceFactory, Set<RequestListener> requestListeners, Set<RequestListener2> requestListener2s, Supplier<Boolean> isPrefetchEnabledSupplier, MemoryCache<CacheKeyCloseableImage> bitmapMemoryCache, MemoryCache<CacheKeyPooledByteBuffer> encodedMemoryCache, BufferedDiskCache mainBufferedDiskCache, BufferedDiskCache smallImageBufferedDiskCache, CacheKeyFactory cacheKeyFactory, ThreadHandoffProducerQueue threadHandoffProducerQueue, Supplier<Boolean> suppressBitmapPrefetchingSupplier, Supplier<Boolean> lazyDataSource, CallerContextVerifier callerContextVerifier, ImagePipelineConfig config)

Public Methods

public void clearCaches ()

Clear all the caches (memory and disk)

public void clearDiskCaches ()

Clear disk caches

public void clearMemoryCaches ()

Clear the memory caches

public void evictFromCache (Uri uri)

If you have supplied your own cache key factory when configuring the pipeline, this method may not work correctly. It will only work if the custom factory builds the cache key entirely from the URI. If that is not the case, use evictFromMemoryCache(Uri) and evictFromDiskCache(ImageRequest) separately.

Parameters
uri The uri of the image to evict

public void evictFromDiskCache (Uri uri)

If you have supplied your own cache key factory when configuring the pipeline, this method may not work correctly. It will only work if the custom factory builds the cache key entirely from the URI. If that is not the case, use evictFromDiskCache(ImageRequest).

Parameters
uri The uri of the image to evict

public void evictFromDiskCache (ImageRequest imageRequest)

Removes all images with the specified Uri from disk cache.

Parameters
imageRequest The imageRequest for the image to evict from disk cache

public void evictFromMemoryCache (Uri uri)

Removes all images with the specified Uri from memory cache.

Parameters
uri The uri of the image to evict

public DataSource<CloseableReference<CloseableImage>> fetchDecodedImage (ImageRequest imageRequest, Object callerContext, ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit, RequestListener requestListener)

Submits a request for execution and returns a DataSource representing the pending decoded image(s).

The returned DataSource must be closed once the client has finished with it.

Parameters
imageRequest the request to submit
callerContext the caller context for image request
lowestPermittedRequestLevelOnSubmit the lowest request level permitted for image reques
requestListener additional image request listener independent of ImageRequest listeners
Returns
  • a DataSource representing the pending decoded image(s)

public DataSource<CloseableReference<CloseableImage>> fetchDecodedImage (ImageRequest imageRequest, Object callerContext)

Submits a request for execution and returns a DataSource representing the pending decoded image(s).

The returned DataSource must be closed once the client has finished with it.

Parameters
imageRequest the request to submit
callerContext the caller context for image request
Returns
  • a DataSource representing the pending decoded image(s)

public DataSource<CloseableReference<CloseableImage>> fetchDecodedImage (ImageRequest imageRequest, Object callerContext, RequestListener requestListener)

Submits a request for execution and returns a DataSource representing the pending decoded image(s).

The returned DataSource must be closed once the client has finished with it.

Parameters
imageRequest the request to submit
callerContext the caller context for image request
requestListener additional image request listener independent of ImageRequest listeners
Returns
  • a DataSource representing the pending decoded image(s)

public DataSource<CloseableReference<CloseableImage>> fetchDecodedImage (ImageRequest imageRequest, Object callerContext, ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit)

Submits a request for execution and returns a DataSource representing the pending decoded image(s).

The returned DataSource must be closed once the client has finished with it.

Parameters
imageRequest the request to submit
callerContext the caller context for image request
lowestPermittedRequestLevelOnSubmit the lowest request level permitted for image request
Returns
  • a DataSource representing the pending decoded image(s)

public DataSource<CloseableReference<CloseableImage>> fetchDecodedImage (ImageRequest imageRequest, Object callerContext, ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit, RequestListener requestListener, String uiComponentId)

Submits a request for execution and returns a DataSource representing the pending decoded image(s).

The returned DataSource must be closed once the client has finished with it.

Parameters
imageRequest the request to submit
callerContext the caller context for image request
lowestPermittedRequestLevelOnSubmit the lowest request level permitted for image reques
requestListener additional image request listener independent of ImageRequest listeners
uiComponentId optional UI component ID that is requesting the image
Returns
  • a DataSource representing the pending decoded image(s)

public DataSource<CloseableReference<PooledByteBuffer>> fetchEncodedImage (ImageRequest imageRequest, Object callerContext, RequestListener requestListener)

Submits a request for execution and returns a DataSource representing the pending encoded image(s).

The ResizeOptions in the imageRequest will be ignored for this fetch

The returned DataSource must be closed once the client has finished with it.

Parameters
imageRequest the request to submit
Returns
  • a DataSource representing the pending encoded image(s)

public DataSource<CloseableReference<PooledByteBuffer>> fetchEncodedImage (ImageRequest imageRequest, Object callerContext)

Submits a request for execution and returns a DataSource representing the pending encoded image(s).

The ResizeOptions in the imageRequest will be ignored for this fetch

The returned DataSource must be closed once the client has finished with it.

Parameters
imageRequest the request to submit
Returns
  • a DataSource representing the pending encoded image(s)

public DataSource<CloseableReference<CloseableImage>> fetchImageFromBitmapCache (ImageRequest imageRequest, Object callerContext)

Submits a request for bitmap cache lookup.

Parameters
imageRequest the request to submit
callerContext the caller context for image request
Returns
  • a DataSource representing the image

public String generateUniqueFutureId ()

Generates unique id for RequestFuture.

Returns
  • unique id

public MemoryCache<CacheKeyCloseableImage> getBitmapMemoryCache ()

Returns
  • The Bitmap MemoryCache

public CacheKey getCacheKey (ImageRequest imageRequest, Object callerContext)

Returns
  • CacheKey for doing bitmap cache lookups in the pipeline.

public CacheKeyFactory getCacheKeyFactory ()

Returns
  • The CacheKeyFactory implementation used by ImagePipeline

public CloseableReference<CloseableImage> getCachedImage (CacheKey cacheKey)

Returns a reference to the cached image

Returns
  • a closeable reference or null if image was not present in cache

public RequestListener getCombinedRequestListener (RequestListener listener)

public ImagePipelineConfig getConfig ()

public Supplier<DataSource<CloseableReference<CloseableImage>>> getDataSourceSupplier (ImageRequest imageRequest, Object callerContext, ImageRequest.RequestLevel requestLevel)

Returns a DataSource supplier that will on get submit the request for execution and return a DataSource representing the pending results of the task.

Parameters
imageRequest the request to submit (what to execute).
callerContext the caller context of the caller of data source supplier
requestLevel which level to look down until for the image
Returns
  • a DataSource representing pending results and completion of the request

public Supplier<DataSource<CloseableReference<CloseableImage>>> getDataSourceSupplier (ImageRequest imageRequest, Object callerContext, ImageRequest.RequestLevel requestLevel, RequestListener requestListener)

Returns a DataSource supplier that will on get submit the request for execution and return a DataSource representing the pending results of the task.

Parameters
imageRequest the request to submit (what to execute).
callerContext the caller context of the caller of data source supplier
requestLevel which level to look down until for the image
requestListener additional image request listener independent of ImageRequest listeners
Returns
  • a DataSource representing pending results and completion of the request

public Supplier<DataSource<CloseableReference<CloseableImage>>> getDataSourceSupplier (ImageRequest imageRequest, Object callerContext, ImageRequest.RequestLevel requestLevel, RequestListener requestListener, String uiComponentId)

Returns a DataSource supplier that will on get submit the request for execution and return a DataSource representing the pending results of the task.

Parameters
imageRequest the request to submit (what to execute).
callerContext the caller context of the caller of data source supplier
requestLevel which level to look down until for the image
requestListener additional image request listener independent of ImageRequest listeners
uiComponentId optional UI component ID requesting the image
Returns
  • a DataSource representing pending results and completion of the request

public Supplier<DataSource<CloseableReference<PooledByteBuffer>>> getEncodedImageDataSourceSupplier (ImageRequest imageRequest, Object callerContext)

Returns a DataSource supplier that will on get submit the request for execution and return a DataSource representing the pending results of the task.

Parameters
imageRequest the request to submit (what to execute).
Returns
  • a DataSource representing pending results and completion of the request

public ProducerSequenceFactory getProducerSequenceFactory ()

public RequestListener getRequestListenerForRequest (ImageRequest imageRequest, RequestListener requestListener)

public long getUsedDiskCacheSize ()

Current disk caches size

Returns
  • size in Bytes

public boolean hasCachedImage (CacheKey cacheKey)

public boolean isInBitmapMemoryCache (ImageRequest imageRequest)

Returns whether the image is stored in the bitmap memory cache.

Parameters
imageRequest the imageRequest for the image to be looked up.
Returns
  • true if the image was found in the bitmap memory cache, false otherwise.

public boolean isInBitmapMemoryCache (Uri uri)

Returns whether the image is stored in the bitmap memory cache.

Parameters
uri the uri for the image to be looked up.
Returns
  • true if the image was found in the bitmap memory cache, false otherwise

public DataSource<Boolean> isInDiskCache (ImageRequest imageRequest)

Returns whether the image is stored in the disk cache.

Parameters
imageRequest the imageRequest for the image to be looked up.
Returns
  • true if the image was found in the disk cache, false otherwise.

public DataSource<Boolean> isInDiskCache (Uri uri)

Returns whether the image is stored in the disk cache.

If you have supplied your own cache key factory when configuring the pipeline, this method may not work correctly. It will only work if the custom factory builds the cache key entirely from the URI. If that is not the case, use isInDiskCache(ImageRequest).

Parameters
uri the uri for the image to be looked up.
Returns
  • true if the image was found in the disk cache, false otherwise.

public boolean isInDiskCacheSync (Uri uri)

Returns whether the image is stored in the disk cache. Performs disk cache check synchronously. It is not recommended to use this unless you know what exactly you are doing. Disk cache check is a costly operation, the call will block the caller thread until the cache check is completed.

Parameters
uri the uri for the image to be looked up.
Returns
  • true if the image was found in the disk cache, false otherwise.

public boolean isInDiskCacheSync (Uri uri, ImageRequest.CacheChoice cacheChoice)

Returns whether the image is stored in the disk cache. Performs disk cache check synchronously. It is not recommended to use this unless you know what exactly you are doing. Disk cache check is a costly operation, the call will block the caller thread until the cache check is completed.

Parameters
uri the uri for the image to be looked up.
cacheChoice the cacheChoice for the cache to be looked up.
Returns
  • true if the image was found in the disk cache, false otherwise.

public boolean isInDiskCacheSync (ImageRequest imageRequest)

Performs disk cache check synchronously. It is not recommended to use this unless you know what exactly you are doing. Disk cache check is a costly operation, the call will block the caller thread until the cache check is completed.

Parameters
imageRequest the imageRequest for the image to be looked up.
Returns
  • true if the image was found in the disk cache, false otherwise.

public boolean isInEncodedMemoryCache (Uri uri)

Returns whether the image is stored in the encoded memory cache.

Parameters
uri the uri for the image to be looked up.
Returns
  • true if the image was found in the encoded memory cache, false otherwise

public boolean isInEncodedMemoryCache (ImageRequest imageRequest)

Returns whether the image is stored in the encoded memory cache.

Parameters
imageRequest the imageRequest for the image to be looked up.
Returns
  • true if the image was found in the encoded memory cache, false otherwise.

public Supplier<Boolean> isLazyDataSource ()

public boolean isPaused ()

public void pause ()

public DataSource<Void> prefetchToBitmapCache (ImageRequest imageRequest, Object callerContext, RequestListener requestListener)

public DataSource<Void> prefetchToBitmapCache (ImageRequest imageRequest, Object callerContext)

Submits a request for prefetching to the bitmap cache.

Beware that if your network fetcher doesn't support priorities prefetch requests may slow down images which are immediately required on screen.

Parameters
imageRequest the request to submit
Returns
  • a DataSource that can safely be ignored.

public DataSource<Void> prefetchToDiskCache (ImageRequest imageRequest, Object callerContext, RequestListener requestListener)

public DataSource<Void> prefetchToDiskCache (ImageRequest imageRequest, Object callerContext, Priority priority)

Submits a request for prefetching to the disk cache.

Beware that if your network fetcher doesn't support priorities prefetch requests may slow down images which are immediately required on screen.

Parameters
imageRequest the request to submit
priority custom priority for the fetch
Returns
  • a DataSource that can safely be ignored.

public DataSource<Void> prefetchToDiskCache (ImageRequest imageRequest, Object callerContext, Priority priority, RequestListener requestListener)

public DataSource<Void> prefetchToDiskCache (ImageRequest imageRequest, Object callerContext)

Submits a request for prefetching to the disk cache with a default priority.

Beware that if your network fetcher doesn't support priorities prefetch requests may slow down images which are immediately required on screen.

Parameters
imageRequest the request to submit
Returns
  • a DataSource that can safely be ignored.

public DataSource<Void> prefetchToEncodedCache (ImageRequest imageRequest, Object callerContext)

Submits a request for prefetching to the encoded cache with a default priority.

Beware that if your network fetcher doesn't support priorities prefetch requests may slow down images which are immediately required on screen.

Parameters
imageRequest the request to submit
Returns
  • a DataSource that can safely be ignored.

public DataSource<Void> prefetchToEncodedCache (ImageRequest imageRequest, Object callerContext, RequestListener requestListener)

public DataSource<Void> prefetchToEncodedCache (ImageRequest imageRequest, Object callerContext, Priority priority)

Submits a request for prefetching to the encoded cache.

Beware that if your network fetcher doesn't support priorities prefetch requests may slow down images which are immediately required on screen.

Parameters
imageRequest the request to submit
priority custom priority for the fetch
Returns
  • a DataSource that can safely be ignored.

public DataSource<Void> prefetchToEncodedCache (ImageRequest imageRequest, Object callerContext, Priority priority, RequestListener requestListener)

public void resume ()

public DataSource<CloseableReference<T>> submitFetchRequest (Producer<CloseableReference<T>> producerSequence, SettableProducerContext settableProducerContext, RequestListener requestListener)