From a57e0f7e131b3a0d5dea4a93569c1820d398fc02 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Fri, 15 Jun 2018 22:55:35 +0800 Subject: [PATCH] fix that SDImageCache does not use transformed key to query cache when provide a transformer --- SDWebImage/SDImageCache.m | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index 3ae01792..4cab242a 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -344,6 +344,13 @@ return nil; } + if ([context valueForKey:SDWebImageContextImageTransformer]) { + // grab the transformed disk image if transformer provided + id transformer = [context valueForKey:SDWebImageContextImageTransformer]; + NSString *transformerKey = [transformer transformerKey]; + key = SDTransformedKeyForKey(key, transformerKey); + } + // First check the in-memory cache... UIImage *image = [self imageFromMemoryCacheForKey:key]; BOOL shouldQueryMemoryOnly = (image && !(options & SDImageCacheQueryMemoryData)); @@ -376,18 +383,11 @@ diskImage = image; cacheType = SDImageCacheTypeMemory; } else if (diskData) { - NSString *cacheKey = key; - if ([context valueForKey:SDWebImageContextImageTransformer]) { - // grab the transformed disk image if transformer provided - id transformer = [context valueForKey:SDWebImageContextImageTransformer]; - NSString *transformerKey = [transformer transformerKey]; - cacheKey = SDTransformedKeyForKey(key, transformerKey); - } // decode image data only if in-memory cache missed - diskImage = [self diskImageForKey:cacheKey data:diskData options:options context:context]; + diskImage = [self diskImageForKey:key data:diskData options:options context:context]; if (diskImage && self.config.shouldCacheImagesInMemory) { NSUInteger cost = SDMemoryCacheCostForImage(diskImage); - [self.memCache setObject:diskImage forKey:cacheKey cost:cost]; + [self.memCache setObject:diskImage forKey:key cost:cost]; } } @@ -698,7 +698,9 @@ - (void)clearWithCacheType:(SDImageCacheType)cacheType completion:(SDWebImageNoParamsBlock)completionBlock { switch (cacheType) { case SDImageCacheTypeNone: { - return; + if (completionBlock) { + completionBlock(); + } } break; case SDImageCacheTypeMemory: {