Merge pull request #2359 from dreampiggy/fix_transformer_cache_key

fix that SDImageCache does not use transformed key to query cache when provide a transformer
This commit is contained in:
DreamPiggy 2018-06-16 00:09:32 +08:00 committed by GitHub
commit fcc53f9e08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 10 deletions

View File

@ -344,6 +344,13 @@
return nil;
}
if ([context valueForKey:SDWebImageContextImageTransformer]) {
// grab the transformed disk image if transformer provided
id<SDImageTransformer> 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<SDImageTransformer> 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: {