fix query disk image cache to memory bug

This commit is contained in:
kinarobin 2021-01-15 11:48:58 +08:00
parent 564d238f88
commit 83183150bb
1 changed files with 7 additions and 1 deletions

View File

@ -361,7 +361,13 @@ static NSString * _defaultDiskCacheDirectory;
- (nullable UIImage *)imageFromDiskCacheForKey:(nullable NSString *)key options:(SDImageCacheOptions)options context:(nullable SDWebImageContext *)context { - (nullable UIImage *)imageFromDiskCacheForKey:(nullable NSString *)key options:(SDImageCacheOptions)options context:(nullable SDWebImageContext *)context {
NSData *data = [self diskImageDataForKey:key]; NSData *data = [self diskImageDataForKey:key];
UIImage *diskImage = [self diskImageForKey:key data:data options:options context:context]; UIImage *diskImage = [self diskImageForKey:key data:data options:options context:context];
if (diskImage && self.config.shouldCacheImagesInMemory) {
BOOL shouldCacheToMomery = YES;
if (context[SDWebImageContextStoreCacheType]) {
SDImageCacheType cacheType = [context[SDWebImageContextStoreCacheType] integerValue];
shouldCacheToMomery = (cacheType == SDImageCacheTypeAll || cacheType == SDImageCacheTypeMemory);
}
if (diskImage && self.config.shouldCacheImagesInMemory && shouldCacheToMomery) {
NSUInteger cost = diskImage.sd_memoryCost; NSUInteger cost = diskImage.sd_memoryCost;
[self.memoryCache setObject:diskImage forKey:key cost:cost]; [self.memoryCache setObject:diskImage forKey:key cost:cost];
} }