From c2c4d14bea82e5c7525393ef03095d02742c321a Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Fri, 19 Feb 2021 16:06:25 +0800 Subject: [PATCH] Sync the SDImageCache logic from SDWebImage 5.10.0 --- SDWebImagePINPlugin/Classes/PINCache+SDAdditions.m | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/SDWebImagePINPlugin/Classes/PINCache+SDAdditions.m b/SDWebImagePINPlugin/Classes/PINCache+SDAdditions.m index 14390bf..17db5e9 100644 --- a/SDWebImagePINPlugin/Classes/PINCache+SDAdditions.m +++ b/SDWebImagePINPlugin/Classes/PINCache+SDAdditions.m @@ -111,16 +111,18 @@ @implementation PINCache (SDAdditions) @autoreleasepool { UIImage *diskImage; - SDImageCacheType cacheType = SDImageCacheTypeNone; if (image) { // the image is from in-memory cache, but need image data diskImage = image; - cacheType = SDImageCacheTypeMemory; } else if (diskData) { - cacheType = SDImageCacheTypeDisk; + BOOL shouldCacheToMomery = YES; + if (context[SDWebImageContextStoreCacheType]) { + SDImageCacheType cacheType = [context[SDWebImageContextStoreCacheType] integerValue]; + shouldCacheToMomery = (cacheType == SDImageCacheTypeAll || cacheType == SDImageCacheTypeMemory); + } // decode image data only if in-memory cache missed diskImage = SDImageCacheDecodeImageData(diskData, key, options, context); - if (diskImage) { + if (shouldCacheToMomery && diskImage) { // Check extended data NSData *extendedData = [self.diskCache extendedDataForKey:key]; if (extendedData) { @@ -154,10 +156,10 @@ @implementation PINCache (SDAdditions) if (doneBlock) { if (shouldQueryDiskSync) { - doneBlock(diskImage, diskData, cacheType); + doneBlock(diskImage, diskData, SDImageCacheTypeDisk); } else { dispatch_async(dispatch_get_main_queue(), ^{ - doneBlock(diskImage, diskData, cacheType); + doneBlock(diskImage, diskData, SDImageCacheTypeDisk); }); } }