From 83183150bba750650758dd66fba7487c65c05888 Mon Sep 17 00:00:00 2001 From: kinarobin Date: Fri, 15 Jan 2021 11:48:58 +0800 Subject: [PATCH] fix query disk image cache to memory bug --- SDWebImage/Core/SDImageCache.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/SDWebImage/Core/SDImageCache.m b/SDWebImage/Core/SDImageCache.m index 67d9e8c7..e9f1d584 100644 --- a/SDWebImage/Core/SDImageCache.m +++ b/SDWebImage/Core/SDImageCache.m @@ -361,7 +361,13 @@ static NSString * _defaultDiskCacheDirectory; - (nullable UIImage *)imageFromDiskCacheForKey:(nullable NSString *)key options:(SDImageCacheOptions)options context:(nullable SDWebImageContext *)context { NSData *data = [self diskImageDataForKey:key]; 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; [self.memoryCache setObject:diskImage forKey:key cost:cost]; }