diff --git a/Source/ASMultiplexImageNode.mm b/Source/ASMultiplexImageNode.mm index 7c3bd881e..926480a05 100644 --- a/Source/ASMultiplexImageNode.mm +++ b/Source/ASMultiplexImageNode.mm @@ -806,7 +806,7 @@ - (void)_fetchImageWithIdentifierFromCache:(id)imageIdentifier URL:(NSURL *)imag ASDisplayNodeAssertNotNil(completionBlock, @"completionBlock is required"); if (_cache) { - [_cache cachedImageWithURL:imageURL callbackQueue:dispatch_get_main_queue() completion:^(id imageContainer) { + [_cache cachedImageWithURL:imageURL callbackQueue:dispatch_get_main_queue() completion:^(id imageContainer, __unused ASImageCacheType cacheType ) { completionBlock([imageContainer asdk_image]); }]; } diff --git a/Source/ASNetworkImageNode.mm b/Source/ASNetworkImageNode.mm index f3a9638cb..daf3a47c1 100644 --- a/Source/ASNetworkImageNode.mm +++ b/Source/ASNetworkImageNode.mm @@ -867,7 +867,7 @@ - (void)_lazilyLoadImageIfNecessary as_log_verbose(ASImageLoadingLog(), "Decaching image for %@ url: %@", self, URL); - ASImageCacherCompletion completion = ^(id imageContainer) { + ASImageCacherCompletion completion = ^(id imageContainer, ASImageCacheType cacheType) { // If the cache sentinel changed, that means this request was cancelled. if (ASLockedSelf(self->_cacheSentinel != cacheSentinel)) { return; @@ -887,8 +887,8 @@ - (void)_lazilyLoadImageIfNecessary if (delegateDidLoadImageFromCache) { [delegate imageNodeDidLoadImageFromCache:self]; } - as_log_verbose(ASImageLoadingLog(), "Decached image for %@ img: %@ url: %@", self, [imageContainer asdk_image], URL); - finished(imageContainer, nil, nil, ASNetworkImageSourceAsynchronousCache, nil); + as_log_verbose(ASImageLoadingLog(), "Decached image for %@ img: %@ url: %@ cacheType: %@", self, [imageContainer asdk_image], URL, cacheType); + finished(imageContainer, nil, nil, cacheType == ASImageCacheTypeSynchronous ? ASNetworkImageSourceSynchronousCache : ASNetworkImageSourceAsynchronousCache, nil); } }; diff --git a/Source/Details/ASImageProtocols.h b/Source/Details/ASImageProtocols.h index fae3b9f5b..d91b8a778 100644 --- a/Source/Details/ASImageProtocols.h +++ b/Source/Details/ASImageProtocols.h @@ -20,7 +20,12 @@ NS_ASSUME_NONNULL_BEGIN @end -typedef void(^ASImageCacherCompletion)(id _Nullable imageFromCache); +typedef NS_ENUM(NSInteger, ASImageCacheType) { + ASImageCacheTypeAsynchronous = 0, + ASImageCacheTypeSynchronous, +}; + +typedef void(^ASImageCacherCompletion)(id _Nullable imageFromCache, ASImageCacheType cacheType); @protocol ASImageCacheProtocol diff --git a/Source/Details/ASPINRemoteImageDownloader.mm b/Source/Details/ASPINRemoteImageDownloader.mm index 3daf06e33..df538f019 100644 --- a/Source/Details/ASPINRemoteImageDownloader.mm +++ b/Source/Details/ASPINRemoteImageDownloader.mm @@ -231,14 +231,15 @@ - (void)cachedImageWithURL:(NSURL *)URL { [[self sharedPINRemoteImageManager] imageFromCacheWithURL:URL processorKey:nil options:PINRemoteImageManagerDownloadOptionsSkipDecode completion:^(PINRemoteImageManagerResult * _Nonnull result) { [ASPINRemoteImageDownloader _performWithCallbackQueue:callbackQueue work:^{ + ASImageCacheType cacheType = (result.resultType == PINRemoteImageResultTypeMemoryCache ? ASImageCacheTypeSynchronous : ASImageCacheTypeAsynchronous); #if PIN_ANIMATED_AVAILABLE if (result.alternativeRepresentation) { - completion(result.alternativeRepresentation); + completion(result.alternativeRepresentation, cacheType); } else { - completion(result.image); + completion(result.image, cacheType); } #else - completion(result.image); + completion(result.image, cacheType); #endif }]; }]; diff --git a/Tests/ASMultiplexImageNodeTests.mm b/Tests/ASMultiplexImageNodeTests.mm index 53d1c67fc..8ebd77c45 100644 --- a/Tests/ASMultiplexImageNodeTests.mm +++ b/Tests/ASMultiplexImageNodeTests.mm @@ -112,7 +112,7 @@ - (void)testDataSourceURLMethod OCMExpect([mockCache cachedImageWithURL:[self _testImageURL] callbackQueue:OCMOCK_ANY completion:[OCMArg isNotNil]]) .andDo(^(NSInvocation *inv) { ASImageCacherCompletion completionBlock = [inv as_argumentAtIndexAsObject:4]; - completionBlock([self _testImage]); + completionBlock([self _testImage], ASImageCacheTypeAsynchronous); }); imageNode.imageIdentifiers = @[imageIdentifier]; @@ -217,7 +217,7 @@ - (void)testUncachedDownload OCMExpect([mockCache cachedImageWithURL:[self _testImageURL] callbackQueue:OCMOCK_ANY completion:[OCMArg isNotNil]]) .andDo(^(NSInvocation *inv){ ASImageCacherCompletion completion = [inv as_argumentAtIndexAsObject:4]; - completion(nil); + completion(nil, ASImageCacheTypeAsynchronous); }); // Mock a 50%-progress URL download. diff --git a/Tests/ASNetworkImageNodeTests.mm b/Tests/ASNetworkImageNodeTests.mm index f794ba9e7..d0853c1c1 100644 --- a/Tests/ASNetworkImageNodeTests.mm +++ b/Tests/ASNetworkImageNodeTests.mm @@ -109,7 +109,7 @@ @implementation ASTestImageCache - (void)cachedImageWithURL:(NSURL *)URL callbackQueue:(dispatch_queue_t)callbackQueue completion:(ASImageCacherCompletion)completion { - completion(nil); + completion(nil, ASImageCacheTypeAsynchronous); } @end