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 1 commit
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, BOOL isFromMemoryCache) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[_cache cachedImageWithURL:imageURL callbackQueue:dispatch_get_main_queue() completion:^(id <ASImageContainerProtocol> imageContainer, BOOL isFromMemoryCache) {
[_cache cachedImageWithURL:imageURL callbackQueue:dispatch_get_main_queue() completion:^(id <ASImageContainerProtocol> imageContainer, __unused BOOL isFromMemoryCache) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually wasn't the intention originally. The protocol is in place so any library can provide image downloading and caching either synchronously or asynchronously. It wasn't intended that Texture would know how the cache is backed. I'm guessing some coupling between PINRemoteImage and Texture has crept back in…

I would recommend reporting async / sync?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jparise Done

@garrettmoon Thanks for the context, have updated to use ansync/sync terminology.

completionBlock([imageContainer asdk_image]);
}];
}
Expand Down
4 changes: 2 additions & 2 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, BOOL isFromMemoryCache) {
// If the cache sentinel changed, that means this request was cancelled.
if (ASLockedSelf(self->_cacheSentinel != cacheSentinel)) {
return;
Expand All @@ -888,7 +888,7 @@ - (void)_lazilyLoadImageIfNecessary
[delegate imageNodeDidLoadImageFromCache:self];
}
as_log_verbose(ASImageLoadingLog(), "Decached image for %@ img: %@ url: %@", self, [imageContainer asdk_image], URL);
jparise marked this conversation as resolved.
Show resolved Hide resolved
finished(imageContainer, nil, nil, ASNetworkImageSourceAsynchronousCache, nil);
finished(imageContainer, nil, nil, isFromMemoryCache ? ASNetworkImageSourceSynchronousCache : ASNetworkImageSourceAsynchronousCache, nil);
}
};

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

@end

typedef void(^ASImageCacherCompletion)(id <ASImageContainerProtocol> _Nullable imageFromCache);
typedef void(^ASImageCacherCompletion)(id <ASImageContainerProtocol> _Nullable imageFromCache, BOOL isFromMemoryCache);

@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:^{
const BOOL isFromMemoryCache = result.resultType == PINRemoteImageResultTypeMemoryCache;
#if PIN_ANIMATED_AVAILABLE
if (result.alternativeRepresentation) {
completion(result.alternativeRepresentation);
completion(result.alternativeRepresentation, isFromMemoryCache);
} else {
completion(result.image);
completion(result.image, isFromMemoryCache);
}
#else
completion(result.image);
completion(result.image, isFromMemoryCache);
#endif
}];
}];
Expand Down