in imagepipeline/src/main/java/com/facebook/imagepipeline/producers/EncodedMemoryCacheProducer.java [145:194]
public void onNewResultImpl(@Nullable EncodedImage newResult, @Status int status) {
try {
if (FrescoSystrace.isTracing()) {
FrescoSystrace.beginSection("EncodedMemoryCacheProducer#onNewResultImpl");
}
// intermediate, null or uncacheable results are not cached, so we just forward them
// as well as the images with unknown format which could be html response from the server
if (isNotLast(status)
|| newResult == null
|| statusHasAnyFlag(status, DO_NOT_CACHE_ENCODED | IS_PARTIAL_RESULT)
|| newResult.getImageFormat() == ImageFormat.UNKNOWN) {
getConsumer().onNewResult(newResult, status);
return;
}
// cache and forward the last result
CloseableReference<PooledByteBuffer> ref = newResult.getByteBufferRef();
if (ref != null) {
CloseableReference<PooledByteBuffer> cachedResult = null;
try {
if (mEncodedCacheEnabled && mIsEncodedCacheEnabledForWrite) {
cachedResult = mMemoryCache.cache(mRequestedCacheKey, ref);
}
} finally {
CloseableReference.closeSafely(ref);
}
if (cachedResult != null) {
EncodedImage cachedEncodedImage;
try {
cachedEncodedImage = new EncodedImage(cachedResult);
cachedEncodedImage.copyMetaDataFrom(newResult);
} finally {
CloseableReference.closeSafely(cachedResult);
}
try {
getConsumer().onProgressUpdate(1f);
getConsumer().onNewResult(cachedEncodedImage, status);
return;
} finally {
EncodedImage.closeSafely(cachedEncodedImage);
}
}
}
getConsumer().onNewResult(newResult, status);
} finally {
if (FrescoSystrace.isTracing()) {
FrescoSystrace.endSection();
}
}
}