From e7e9268a7e9c2f1157f1cea1b88465bc1589b4f9 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Thu, 23 Jun 2022 17:54:27 +0800 Subject: [PATCH] Fix the case that query full size key with thumbnail, cause the write back of thumnail to memory cache with wrong key --- SDWebImage/Core/SDImageCache.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/SDWebImage/Core/SDImageCache.m b/SDWebImage/Core/SDImageCache.m index a083b6ac..1e40f567 100644 --- a/SDWebImage/Core/SDImageCache.m +++ b/SDWebImage/Core/SDImageCache.m @@ -373,7 +373,11 @@ static NSString * _defaultDiskCacheDirectory; SDImageCacheType cacheType = [context[SDWebImageContextStoreCacheType] integerValue]; shouldCacheToMomery = (cacheType == SDImageCacheTypeAll || cacheType == SDImageCacheTypeMemory); } - if (diskImage && self.config.shouldCacheImagesInMemory && shouldCacheToMomery) { + if (context[SDWebImageContextImageThumbnailPixelSize]) { + // Query full size cache key which generate a thumbnail, should not write back to full size memory cache + shouldCacheToMomery = NO; + } + if (shouldCacheToMomery && diskImage && self.config.shouldCacheImagesInMemory) { NSUInteger cost = diskImage.sd_memoryCost; [self.memoryCache setObject:diskImage forKey:key cost:cost]; } @@ -581,6 +585,10 @@ static NSString * _defaultDiskCacheDirectory; SDImageCacheType cacheType = [context[SDWebImageContextStoreCacheType] integerValue]; shouldCacheToMomery = (cacheType == SDImageCacheTypeAll || cacheType == SDImageCacheTypeMemory); } + if (context[SDWebImageContextImageThumbnailPixelSize]) { + // Query full size cache key which generate a thumbnail, should not write back to full size memory cache + shouldCacheToMomery = NO; + } // decode image data only if in-memory cache missed diskImage = [self diskImageForKey:key data:diskData options:options context:context]; if (shouldCacheToMomery && diskImage && self.config.shouldCacheImagesInMemory) {