Merge pull request #3523 from dreampiggy/opt/same_url_query_extra_decode_store
Performance: Opt when multiple same URL query in parallels, which may cause duplicated decode and store disk operation
This commit is contained in:
commit
5481aa2e16
|
@ -668,11 +668,17 @@ static NSString * _defaultDiskCacheDirectory;
|
||||||
// Query full size cache key which generate a thumbnail, should not write back to full size memory cache
|
// Query full size cache key which generate a thumbnail, should not write back to full size memory cache
|
||||||
shouldCacheToMomery = NO;
|
shouldCacheToMomery = NO;
|
||||||
}
|
}
|
||||||
|
// Special case: If user query image in list for the same URL, to avoid decode and write **same** image object into disk cache multiple times, we query and check memory cache here again.
|
||||||
|
if (shouldCacheToMomery && self.config.shouldCacheImagesInMemory) {
|
||||||
|
diskImage = [self.memoryCache objectForKey:key];
|
||||||
|
}
|
||||||
// decode image data only if in-memory cache missed
|
// decode image data only if in-memory cache missed
|
||||||
diskImage = [self diskImageForKey:key data:diskData options:options context:context];
|
if (!diskImage) {
|
||||||
if (shouldCacheToMomery && diskImage && self.config.shouldCacheImagesInMemory) {
|
diskImage = [self diskImageForKey:key data:diskData options:options context:context];
|
||||||
NSUInteger cost = diskImage.sd_memoryCost;
|
if (shouldCacheToMomery && diskImage && self.config.shouldCacheImagesInMemory) {
|
||||||
[self.memoryCache setObject:diskImage forKey:key cost:cost];
|
NSUInteger cost = diskImage.sd_memoryCost;
|
||||||
|
[self.memoryCache setObject:diskImage forKey:key cost:cost];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return diskImage;
|
return diskImage;
|
||||||
|
|
Loading…
Reference in New Issue