From 2d0f6da51f623fc859a3d328122f0475c6d650c4 Mon Sep 17 00:00:00 2001 From: onevcat Date: Mon, 18 Nov 2019 15:03:46 +0900 Subject: [PATCH] Make sure to skip disk cache when `fromMemoryCacheOrRefresh` set --- Sources/General/KingfisherManager.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Sources/General/KingfisherManager.swift b/Sources/General/KingfisherManager.swift index 654959c88..ae98717cd 100644 --- a/Sources/General/KingfisherManager.swift +++ b/Sources/General/KingfisherManager.swift @@ -497,9 +497,15 @@ public class KingfisherManager { } // Check whether the unprocessed image existing or not. - let originalImageCached = originalCache.imageCachedType( - forKey: key, processorIdentifier: DefaultImageProcessor.default.identifier).cached - if originalImageCached { + let originalImageCacheType = originalCache.imageCachedType( + forKey: key, processorIdentifier: DefaultImageProcessor.default.identifier) + let canAcceptDiskCache = !options.fromMemoryCacheOrRefresh + + let canUseOriginalImageCache = + (canAcceptDiskCache && originalImageCacheType.cached) || + (!canAcceptDiskCache && originalImageCacheType == .memory) + + if canUseOriginalImageCache { // Now we are ready to get found the original image from cache. We need the unprocessed image, so remove // any processor from options first. var optionsWithoutProcessor = options @@ -509,6 +515,7 @@ public class KingfisherManager { result.match( onSuccess: { cacheResult in guard let image = cacheResult.image else { + assertionFailure("The image (under key: \(key) should be existing in the original cache.") return }