From a54d1d7a2f0154211deefc66c875c00710e51a02 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 12 Feb 2018 21:20:49 +0800 Subject: [PATCH] Fix that SDImageCacheQueryDataWhenInMemory should response cacheType to memory cache when the in-memory cache hit (#2218) --- SDWebImage/SDImageCache.m | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index 54bc006d..c275d8d0 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -394,8 +394,13 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { @autoreleasepool { NSData *diskData = [self diskImageDataBySearchingAllPathsForKey:key]; - UIImage *diskImage = image; - if (!diskImage && diskData) { + UIImage *diskImage; + SDImageCacheType cacheType = SDImageCacheTypeDisk; + if (image) { + // the image is from in-memory cache + diskImage = image; + cacheType = SDImageCacheTypeMemory; + } else if (diskData) { // decode image data only if in-memory cache missed diskImage = [self diskImageForKey:key data:diskData]; if (diskImage && self.config.shouldCacheImagesInMemory) { @@ -406,10 +411,10 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { if (doneBlock) { if (options & SDImageCacheQueryDiskSync) { - doneBlock(diskImage, diskData, SDImageCacheTypeDisk); + doneBlock(diskImage, diskData, cacheType); } else { dispatch_async(dispatch_get_main_queue(), ^{ - doneBlock(diskImage, diskData, SDImageCacheTypeDisk); + doneBlock(diskImage, diskData, cacheType); }); } }