Fix the case that query full size key with thumbnail, cause the write back of thumnail to memory cache with wrong key

This commit is contained in:
DreamPiggy 2022-06-23 17:54:27 +08:00
parent 613a2bf988
commit e7e9268a7e
1 changed files with 9 additions and 1 deletions

View File

@ -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) {