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:
DreamPiggy 2023-05-05 18:57:01 +08:00 committed by GitHub
commit 5481aa2e16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

View File

@ -668,13 +668,19 @@ static NSString * _defaultDiskCacheDirectory;
// Query full size cache key which generate a thumbnail, should not write back to full size memory cache
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
if (!diskImage) {
diskImage = [self diskImageForKey:key data:diskData options:options context:context];
if (shouldCacheToMomery && diskImage && self.config.shouldCacheImagesInMemory) {
NSUInteger cost = diskImage.sd_memoryCost;
[self.memoryCache setObject:diskImage forKey:key cost:cost];
}
}
}
return diskImage;
};