Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for images retrieved from the memory cache being reported as disk cache hits. #1722

Merged
merged 6 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/ASMultiplexImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ASImageContainerProtocol> imageContainer) {
[_cache cachedImageWithURL:imageURL callbackQueue:dispatch_get_main_queue() completion:^(id <ASImageContainerProtocol> imageContainer, __unused ASImageCacheType cacheType ) {
completionBlock([imageContainer asdk_image]);
}];
}
Expand Down
6 changes: 3 additions & 3 deletions Source/ASNetworkImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ - (void)_lazilyLoadImageIfNecessary

as_log_verbose(ASImageLoadingLog(), "Decaching image for %@ url: %@", self, URL);

ASImageCacherCompletion completion = ^(id <ASImageContainerProtocol> imageContainer) {
ASImageCacherCompletion completion = ^(id <ASImageContainerProtocol> imageContainer, ASImageCacheType cacheType) {
// If the cache sentinel changed, that means this request was cancelled.
if (ASLockedSelf(self->_cacheSentinel != cacheSentinel)) {
return;
Expand All @@ -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);
}
};

Expand Down
7 changes: 6 additions & 1 deletion Source/Details/ASImageProtocols.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ NS_ASSUME_NONNULL_BEGIN

@end

typedef void(^ASImageCacherCompletion)(id <ASImageContainerProtocol> _Nullable imageFromCache);
typedef NS_ENUM(NSInteger, ASImageCacheType) {
ASImageCacheTypeSynchronous = 0,
ASImageCacheTypeAsynchronous,
};

typedef void(^ASImageCacherCompletion)(id <ASImageContainerProtocol> _Nullable imageFromCache, ASImageCacheType cacheType);

@protocol ASImageCacheProtocol <NSObject>

Expand Down
7 changes: 4 additions & 3 deletions Source/Details/ASPINRemoteImageDownloader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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 source = (result.resultType == PINRemoteImageResultTypeMemoryCache ? ASImageCacheTypeSynchronous : ASImageCacheTypeAsynchronous);
jparise marked this conversation as resolved.
Show resolved Hide resolved
#if PIN_ANIMATED_AVAILABLE
if (result.alternativeRepresentation) {
completion(result.alternativeRepresentation);
completion(result.alternativeRepresentation, source);
} else {
completion(result.image);
completion(result.image, source);
}
#else
completion(result.image);
completion(result.image, source);
#endif
}];
}];
Expand Down