public void produceResults(
      final Consumer<EncodedImage> consumer, final ProducerContext producerContext) {
    final ImageRequest imageRequest = producerContext.getImageRequest();
    final boolean isDiskCacheEnabledForRead =
        producerContext
            .getImageRequest()
            .isCacheEnabled(ImageRequest.CachesLocationsMasks.DISK_READ);
    final boolean isDiskCacheEnabledForWrite =
        producerContext
            .getImageRequest()
            .isCacheEnabled(ImageRequest.CachesLocationsMasks.DISK_WRITE);

    if (!isDiskCacheEnabledForRead && !isDiskCacheEnabledForWrite) {
      mInputProducer.produceResults(consumer, producerContext);
      return;
    }

    final ProducerListener2 listener = producerContext.getProducerListener();
    listener.onProducerStart(producerContext, PRODUCER_NAME);

    final Uri uriForPartialCacheKey = createUriForPartialCacheKey(imageRequest);
    final CacheKey partialImageCacheKey =
        mCacheKeyFactory.getEncodedCacheKey(
            imageRequest, uriForPartialCacheKey, producerContext.getCallerContext());

    if (!isDiskCacheEnabledForRead) {
      listener.onProducerFinishWithSuccess(
          producerContext, PRODUCER_NAME, getExtraMap(listener, producerContext, false, 0));
      startInputProducer(consumer, producerContext, partialImageCacheKey, null);
      return;
    }

    final AtomicBoolean isCancelled = new AtomicBoolean(false);
    final Task<EncodedImage> diskLookupTask =
        mDiskCachesStoreSupplier
            .get()
            .getMainBufferedDiskCache()
            .get(partialImageCacheKey, isCancelled);
    final Continuation<EncodedImage, Void> continuation =
        onFinishDiskReads(consumer, producerContext, partialImageCacheKey);

    diskLookupTask.continueWith(continuation);
    subscribeTaskForRequestCancellation(isCancelled, producerContext);
  }
Partial disk cache producer.

<p>This producer looks in the disk cache to see if it holds part of the requested image. If the
image is found, then it is passed to the consumer as a non-final result, but an adjusted request
is still sent further along to request the remainder of the image.

<p>When the final result comes from the input producer, the two parts are stitched back together
and returned as a whole.
imagepipeline/src/main/java/com/facebook/imagepipeline/producers/PartialDiskCacheProducer.java