Просмотр исходного кода

Adopt to Source based image loading

onevcat 7 лет назад
Родитель
Сommit
4dd7567339

+ 11 - 1
Kingfisher.xcodeproj/project.pbxproj

@@ -221,6 +221,10 @@
 		D1E564412199C21E0057AAE3 /* StorageExpirationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1E564402199C21E0057AAE3 /* StorageExpirationTests.swift */; };
 		D1E564422199C21E0057AAE3 /* StorageExpirationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1E564402199C21E0057AAE3 /* StorageExpirationTests.swift */; };
 		D1E564432199C21E0057AAE3 /* StorageExpirationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1E564402199C21E0057AAE3 /* StorageExpirationTests.swift */; };
+		D1E56445219B16330057AAE3 /* ImageDataProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1E56444219B16330057AAE3 /* ImageDataProvider.swift */; };
+		D1E56446219B16330057AAE3 /* ImageDataProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1E56444219B16330057AAE3 /* ImageDataProvider.swift */; };
+		D1E56447219B16330057AAE3 /* ImageDataProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1E56444219B16330057AAE3 /* ImageDataProvider.swift */; };
+		D1E56448219B16330057AAE3 /* ImageDataProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1E56444219B16330057AAE3 /* ImageDataProvider.swift */; };
 		D1ED2D401AD2D09F00CFC3EB /* Kingfisher.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D1ED2D351AD2D09F00CFC3EB /* Kingfisher.framework */; };
 		D9638BA61C7DC71F0046523D /* ImagePrefetcherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9638BA41C7DC71F0046523D /* ImagePrefetcherTests.swift */; };
 		D9638BA71C7DCF560046523D /* ImagePrefetcherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9638BA41C7DC71F0046523D /* ImagePrefetcherTests.swift */; };
@@ -336,6 +340,7 @@
 		D1D2C3291C70A3230018F2F9 /* single-frame.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = "single-frame.gif"; sourceTree = "<group>"; };
 		D1DC4B401D60996D00DFDFAA /* StringExtensionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtensionTests.swift; sourceTree = "<group>"; };
 		D1E564402199C21E0057AAE3 /* StorageExpirationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageExpirationTests.swift; sourceTree = "<group>"; };
+		D1E56444219B16330057AAE3 /* ImageDataProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ImageDataProvider.swift; path = Sources/General/ImageDataProvider.swift; sourceTree = SOURCE_ROOT; };
 		D1ED2D351AD2D09F00CFC3EB /* Kingfisher.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Kingfisher.framework; sourceTree = BUILT_PRODUCTS_DIR; };
 		D1ED2D3F1AD2D09F00CFC3EB /* KingfisherTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = KingfisherTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
 		D7B91E45CD834BE64717E77F /* Pods-KingfisherTests-tvOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-KingfisherTests-tvOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-KingfisherTests-tvOS/Pods-KingfisherTests-tvOS.debug.xcconfig"; sourceTree = "<group>"; };
@@ -463,7 +468,6 @@
 			isa = PBXGroup;
 			children = (
 				D12AB69D215D2BB50013BA68 /* RequestModifier.swift */,
-				D12AB69E215D2BB50013BA68 /* Resource.swift */,
 				D12AB69F215D2BB50013BA68 /* ImageDownloader.swift */,
 				4BD821612189FC0C0084CC21 /* SessionDelegate.swift */,
 				4BD821662189FD330084CC21 /* SessionDataTask.swift */,
@@ -509,6 +513,8 @@
 				D12AB6B2215D2BB50013BA68 /* KingfisherError.swift */,
 				D12AB6B3215D2BB50013BA68 /* KingfisherManager.swift */,
 				D12AB6B4215D2BB50013BA68 /* KingfisherOptionsInfo.swift */,
+				D12AB69E215D2BB50013BA68 /* Resource.swift */,
+				D1E56444219B16330057AAE3 /* ImageDataProvider.swift */,
 				D1A37BEC215D375F009B39B7 /* Deprecated.swift */,
 			);
 			path = General;
@@ -1049,6 +1055,7 @@
 				4B8E291E216F40AA0095FAD1 /* AuthenticationChallengeResponsable.swift in Sources */,
 				D1BA781F2174D07800C69D7B /* CallbackQueue.swift in Sources */,
 				D1A37BD2215D2DBA009B39B7 /* Filter.swift in Sources */,
+				D1E56447219B16330057AAE3 /* ImageDataProvider.swift in Sources */,
 				D1A37BD3215D2DBA009B39B7 /* Placeholder.swift in Sources */,
 				4BD821692189FD330084CC21 /* SessionDataTask.swift in Sources */,
 				D1A37BE0215D34E8009B39B7 /* ImageDrawing.swift in Sources */,
@@ -1120,6 +1127,7 @@
 			files = (
 				D12AB6CD215D2BB50013BA68 /* ImageModifier.swift in Sources */,
 				D12AB719215D2BB50013BA68 /* CacheSerializer.swift in Sources */,
+				D1E56446219B16330057AAE3 /* ImageDataProvider.swift in Sources */,
 				D12AB731215D2BB50013BA68 /* AnimatedImageView.swift in Sources */,
 				4B46CC65217449E000D90C4A /* Storage.swift in Sources */,
 				D12AB6E5215D2BB50013BA68 /* Placeholder.swift in Sources */,
@@ -1201,6 +1209,7 @@
 				4B46CC62217449C600D90C4A /* MemoryStorage.swift in Sources */,
 				D1A37BE6215D359F009B39B7 /* ImageFormat.swift in Sources */,
 				D12AB713215D2BB50013BA68 /* KingfisherOptionsInfo.swift in Sources */,
+				D1E56448219B16330057AAE3 /* ImageDataProvider.swift in Sources */,
 				D1A37BEB215D365A009B39B7 /* ExtenionHelpers.swift in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
@@ -1211,6 +1220,7 @@
 			files = (
 				D12AB6CC215D2BB50013BA68 /* ImageModifier.swift in Sources */,
 				D12AB718215D2BB50013BA68 /* CacheSerializer.swift in Sources */,
+				D1E56445219B16330057AAE3 /* ImageDataProvider.swift in Sources */,
 				D12AB730215D2BB50013BA68 /* AnimatedImageView.swift in Sources */,
 				4B46CC64217449E000D90C4A /* Storage.swift in Sources */,
 				D12AB6E4215D2BB50013BA68 /* Placeholder.swift in Sources */,

+ 1 - 1
Sources/General/Deprecated.swift

@@ -66,7 +66,7 @@ extension KingfisherClass where Base: Image {
 public typealias CompletionHandler =
     ((_ image: Image?, _ error: NSError?, _ cacheType: CacheType, _ imageURL: URL?) -> Void)
 
-@available(*, deprecated, message: "Will be removed soon. Use `Result<ImageDownloadResult>` based callback instead")
+@available(*, deprecated, message: "Will be removed soon. Use `Result<ImageLoadingResult>` based callback instead")
 public typealias ImageDownloaderCompletionHandler =
     ((_ image: Image?, _ error: NSError?, _ url: URL?, _ originalData: Data?) -> Void)
 

+ 73 - 0
Sources/General/ImageDataProvider.swift

@@ -0,0 +1,73 @@
+//
+//  ImageDataProvider.swift
+//  Kingfisher
+//
+//  Created by onevcat on 2018/11/13.
+//
+//  Copyright (c) 2018 Wei Wang <onevcat@gmail.com>
+//
+//  Permission is hereby granted, free of charge, to any person obtaining a copy
+//  of this software and associated documentation files (the "Software"), to deal
+//  in the Software without restriction, including without limitation the rights
+//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+//  copies of the Software, and to permit persons to whom the Software is
+//  furnished to do so, subject to the following conditions:
+//
+//  The above copyright notice and this permission notice shall be included in
+//  all copies or substantial portions of the Software.
+//
+//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+//  THE SOFTWARE.
+
+import Foundation
+
+public protocol ImageDataProvider {
+    var cacheKey: String { get }
+    func data(handler: (Result<Data, Error>) -> Void)
+    var identifier: String {get }
+}
+
+public struct LocalFileImageDataProvider: ImageDataProvider {
+    public var cacheKey: String
+
+    public func data(handler: (Result<Data, Error>) -> Void) {
+        do {
+            let data = try Data(contentsOf: fileURL)
+            handler(.success(data))
+        } catch {
+            handler(
+                .failure(error)
+            )
+        }
+    }
+
+    public var identifier: String { return fileURL.absoluteString }
+
+    public let fileURL: URL
+    public init(fileURL: URL, cacheKey: String? = nil) {
+        self.fileURL = fileURL
+        self.cacheKey = cacheKey ?? fileURL.absoluteString
+    }
+}
+
+public struct Base64ImageDataProvider: ImageDataProvider {
+    public var cacheKey: String
+    public let base64String: String
+    public var identifier: String { return cacheKey }
+
+    public init(base64String: String, cacheKey: String) {
+        self.base64String = base64String
+        self.cacheKey = cacheKey
+    }
+
+    public func data(handler: (Result<Data, Error>) -> Void) {
+        let data = Data(base64Encoded: base64String)!
+        handler(.success(data))
+    }
+
+}

+ 7 - 1
Sources/General/KingfisherError.swift

@@ -157,7 +157,7 @@ public enum KingfisherError: Error {
     ///
     /// - emptyResource: The input resource is empty or `nil`. Code 5001.
     /// - notCurrentResource: The resource task is finished, but it is not the one expected now. Code 5002.
-    
+    /// - dataProviderError: An error happens during getting data from an `ImageDataProvider`. Code 5003.
     public enum ImageSettingErrorReason {
         
         /// The input resource is empty or `nil`. Code 5001.
@@ -168,6 +168,9 @@ public enum KingfisherError: Error {
         /// this `.notCurrentResource` error when a result got, regardless of it being successful or not for that task.
         /// Code 5002.
         case notCurrentResource(result: RetrieveImageResult?, error: Error?, resource: Resource)
+
+        /// An error happens during getting data from an `ImageDataProvider`. Code 5003.
+        case dataProviderError(provider: ImageDataProvider, error: Error)
     }
     
     /// Represents the error reason during networking request phase.
@@ -345,6 +348,8 @@ extension KingfisherError.ImageSettingErrorReason {
             } else {
                 return nil
             }
+        case .dataProviderError(let provider, let error):
+            return "Image data provider fails to provide data. Provider: \(provider), error: \(error)"
         }
     }
     
@@ -352,6 +357,7 @@ extension KingfisherError.ImageSettingErrorReason {
         switch self {
         case .emptyResource: return 5001
         case .notCurrentResource: return 5002
+        case .dataProviderError: return 5003
         }
     }
 }

+ 65 - 45
Sources/General/KingfisherManager.swift

@@ -44,7 +44,7 @@ public struct RetrieveImageResult {
     public let cacheType: CacheType
 
     /// The resource URL of image.
-    public let imageURL: URL
+    public let imageURL: URL?
 }
 
 /// Main manager class of Kingfisher. It connects Kingfisher downloader and cache,
@@ -115,19 +115,27 @@ public class KingfisherManager {
         options: KingfisherOptionsInfo? = nil,
         progressBlock: DownloadProgressBlock? = nil,
         completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)?) -> DownloadTask?
+    {
+        let source = Source.network(resource)
+        return retrieveImage(
+            with: source, options: options, progressBlock: progressBlock, completionHandler: completionHandler
+        )
+    }
+
+    public func retrieveImage(
+        with source: Source,
+        options: KingfisherOptionsInfo? = nil,
+        progressBlock: DownloadProgressBlock? = nil,
+        completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)?) -> DownloadTask?
     {
         let options = currentDefaultOptions + (options ?? .empty)
         if options.forceRefresh {
-            return downloadAndCacheImage(
-                with: resource.downloadURL,
-                forKey: resource.cacheKey,
-                options: options,
-                progressBlock: progressBlock,
-                completionHandler: completionHandler)
+            return loadAndCacheImage(
+                source: source, options: options, progressBlock: progressBlock, completionHandler: completionHandler)
         } else {
             let loadedFromCache = retrieveImageFromCache(
-                forKey: resource.cacheKey,
-                with: resource.downloadURL,
+                forKey: source.cacheKey,
+                with: source.url,
                 options: options,
                 completionHandler: completionHandler)
 
@@ -136,48 +144,47 @@ public class KingfisherManager {
             }
 
             if options.onlyFromCache {
-                let error = KingfisherError.cacheError(reason: .imageNotExisting(key: resource.cacheKey))
+                let error = KingfisherError.cacheError(reason: .imageNotExisting(key: source.cacheKey))
                 completionHandler?(.failure(error))
                 return nil
             }
 
-            return downloadAndCacheImage(
-                with: resource.downloadURL,
-                forKey: resource.cacheKey,
-                options: options,
-                progressBlock: progressBlock,
-                completionHandler: completionHandler)
+            return loadAndCacheImage(
+                source: source, options: options, progressBlock: progressBlock, completionHandler: completionHandler)
+        }
+    }
+
+    func provideImage(
+        provider: ImageDataProvider,
+        options: KingfisherOptionsInfo,
+        completionHandler: ((Result<ImageLoadingResult, KingfisherError>) -> Void)?)
+    {
+        provider.data { result in
+            switch result {
+            case .success(let data):
+                let image = options.processor.process(item: .data(data), options: options)!
+                let result = ImageLoadingResult(image: image, url: nil, originalData: data)
+                completionHandler?(.success(result))
+            case .failure(let error):
+                options.callbackQueue.execute {
+                    completionHandler?(
+                        .failure(.imageSettingError(reason: .dataProviderError(provider: provider, error: error)))
+                    )
+                }
+
+            }
         }
     }
 
-    /// Download and cache the image with given parameters.
-    ///
-    /// - Parameters:
-    ///   - url: The target URL from where the image data could be downloaded.
-    ///   - key: The key to use when caching the image.
-    ///   - options: Options on how to process or serialize the image data.
-    ///   - progressBlock: Called when the image downloading progress gets updated. If the response does not contain an
-    ///                    `expectedContentLength`, this block will not be called. `progressBlock` is always called in
-    ///                    main queue.
-    ///   - completionHandler: Called when the process finishes, either with succeeded
-    ///                        `RetrieveImageResult` or an error.
-    /// - Returns: A task represents the image downloading. If there is no downloading starts, `nil` is returned.
     @discardableResult
-    func downloadAndCacheImage(
-        with url: URL,
-        forKey key: String,
+    func loadAndCacheImage(
+        source: Source,
         options: KingfisherOptionsInfo,
         progressBlock: DownloadProgressBlock? = nil,
         completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)?) -> DownloadTask?
     {
-        let downloader = options.downloader ?? self.downloader
-
-        return downloader.downloadImage(
-            with: url,
-            options: options,
-            progressBlock: progressBlock)
+        func cacheImage(_ result: Result<ImageLoadingResult, KingfisherError>)
         {
-            result in
             switch result {
             case .success(let value):
                 // Add image to cache.
@@ -185,7 +192,7 @@ public class KingfisherManager {
                 targetCache.store(
                     value.image,
                     original: value.originalData,
-                    forKey: key,
+                    forKey: source.cacheKey,
                     processorIdentifier: options.processor.identifier,
                     cacheSerializer: options.cacheSerializer,
                     toDisk: !options.cacheMemoryOnly,
@@ -193,26 +200,26 @@ public class KingfisherManager {
                 {
                     _ in
                     if options.waitForCache {
-                        let result = RetrieveImageResult(image: value.image, cacheType: .none, imageURL: url)
+                        let result = RetrieveImageResult(image: value.image, cacheType: .none, imageURL: value.url)
                         completionHandler?(.success(result))
                     }
                 }
 
                 // Add original image to cache if necessary.
                 let needToCacheOriginalImage = options.cacheOriginalImage &&
-                                               options.processor != DefaultImageProcessor.default
+                    options.processor != DefaultImageProcessor.default
                 if needToCacheOriginalImage {
                     let defaultProcessor = DefaultImageProcessor.default
                     self.processQueue.async {
                         guard let originalImage =
                             defaultProcessor.process(item: .data(value.originalData), options: options)
-                        else { return }
+                            else { return }
 
                         let originalCache = options.originalCache ?? targetCache
                         originalCache.store(
                             originalImage,
                             original: value.originalData,
-                            forKey: key,
+                            forKey: source.cacheKey,
                             processorIdentifier: defaultProcessor.identifier,
                             cacheSerializer: options.cacheSerializer,
                             toDisk: !options.cacheMemoryOnly)
@@ -220,13 +227,26 @@ public class KingfisherManager {
                 }
 
                 if !options.waitForCache {
-                    let result = RetrieveImageResult(image: value.image, cacheType: .none, imageURL: url)
+                    let result = RetrieveImageResult(image: value.image, cacheType: .none, imageURL: value.url)
                     completionHandler?(.success(result))
                 }
             case .failure(let error):
                 completionHandler?(.failure(error))
             }
         }
+
+        switch source {
+        case .network(let resource):
+            let downloader = options.downloader ?? self.downloader
+            return downloader.downloadImage(
+                with: resource.downloadURL,
+                options: options,
+                progressBlock: progressBlock,
+                completionHandler: cacheImage)
+        case .provider(let provider):
+            provideImage(provider: provider, options: options, completionHandler: cacheImage)
+            return nil
+        }
     }
     
     /// Retrieves image from memory or disk cache.
@@ -249,7 +269,7 @@ public class KingfisherManager {
     ///    back to cache for later use.
     func retrieveImageFromCache(
         forKey key: String,
-        with url: URL,
+        with url: URL?,
         options: KingfisherOptionsInfo,
         completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)?) -> Bool
     {

+ 31 - 0
Sources/Networking/Resource.swift → Sources/General/Resource.swift

@@ -26,6 +26,31 @@
 
 import Foundation
 
+public enum Source {
+    case network(Resource)
+    case provider(ImageDataProvider)
+
+    var identifier: String {
+        switch self {
+        case .network(let resource): return resource.identifier
+        case .provider(let provider): return provider.identifier
+        }
+    }
+
+    var cacheKey: String {
+        switch self {
+        case .network(let resource): return resource.cacheKey
+        case .provider(let provider): return provider.cacheKey
+        }
+    }
+
+    var url: URL? {
+        switch self {
+        case .network(let resource): return resource.downloadURL
+        case .provider(_): return nil
+        }
+    }
+}
 
 /// Represents an image resource at a certain url and a given cache key.
 /// Kingfisher will use a `Resource` to download a resource from network and cache it with the cache key.
@@ -35,6 +60,12 @@ public protocol Resource {
     
     /// The target image URL.
     var downloadURL: URL { get }
+
+    var identifier: String {get }
+}
+
+extension Resource {
+    public var identifier: String { return downloadURL.absoluteString }
 }
 
 /// ImageResource is a simple combination of `downloadURL` and `cacheKey`.

+ 6 - 6
Sources/Networking/ImageDownloader.swift

@@ -31,13 +31,13 @@ import UIKit
 #endif
 
 /// Represents a success result of an image downloading progess.
-public struct ImageDownloadResult {
+public struct ImageLoadingResult {
 
     /// The downloaded image.
     public let image: Image
 
     /// Original URL of the image request.
-    public let url: URL
+    public let url: URL?
 
     /// The raw data received from downloader.
     public let originalData: Data
@@ -179,7 +179,7 @@ open class ImageDownloader {
         with url: URL,
         options: KingfisherOptionsInfo? = nil,
         progressBlock: DownloadProgressBlock? = nil,
-        completionHandler: ((Result<ImageDownloadResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
+        completionHandler: ((Result<ImageLoadingResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
     {
         // Creates default request.
         var request = URLRequest(url: url, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: downloadTimeout)
@@ -217,8 +217,8 @@ open class ImageDownloader {
         }
 
         let onCompleted = completionHandler.map {
-            block -> Delegate<Result<ImageDownloadResult, KingfisherError>, Void> in
-            let delegate =  Delegate<Result<ImageDownloadResult, KingfisherError>, Void>()
+            block -> Delegate<Result<ImageLoadingResult, KingfisherError>, Void> in
+            let delegate =  Delegate<Result<ImageLoadingResult, KingfisherError>, Void>()
             delegate.delegate(on: self) { (_, result) in
                 block(result)
             }
@@ -262,7 +262,7 @@ open class ImageDownloader {
                         self.delegate?.imageDownloader(self, didDownload: image, for: url, with: response)
                     }
 
-                    let imageResult = result.map { ImageDownloadResult(image: $0, url: url, originalData: data) }
+                    let imageResult = result.map { ImageLoadingResult(image: $0, url: url, originalData: data) }
                     let queue = callback.options.callbackQueue
                     queue.execute { callback.onCompleted?.call(imageResult) }
                 }

+ 3 - 5
Sources/Networking/ImagePrefetcher.swift

@@ -223,12 +223,10 @@ public class ImagePrefetcher {
                 self.reportCompletionOrStartNext()
             }
         }
-        
-        let downloadTask = manager.downloadAndCacheImage(
-            with: resource.downloadURL,
-            forKey: resource.cacheKey,
+
+        let downloadTask = manager.loadAndCacheImage(
+            source: .network(resource),
             options: optionsInfo,
-            progressBlock: nil,
             completionHandler: downloadTaskCompletionHandler)
         
         if let downloadTask = downloadTask {

+ 1 - 1
Sources/Networking/SessionDataTask.swift

@@ -35,7 +35,7 @@ public class SessionDataTask {
 
     struct TaskCallback {
         let onProgress: Delegate<(Int64, Int64), Void>?
-        let onCompleted: Delegate<Result<ImageDownloadResult, KingfisherError>, Void>?
+        let onCompleted: Delegate<Result<ImageLoadingResult, KingfisherError>, Void>?
         let options: KingfisherOptionsInfo
     }
 

+ 2 - 2
Tests/KingfisherTests/KingfisherManagerTests.swift

@@ -273,7 +273,7 @@ class KingfisherManagerTests: XCTestCase {
         let manager = self.manager!
         let p = SimpleProcessor()
         let options: KingfisherOptionsInfo = [.processor(p), .cacheOriginalImage, .waitForCache]
-        manager.downloadAndCacheImage(with: url, forKey: url.cacheKey, options: options) { result in
+        manager.loadAndCacheImage(source: .network(url), options: options) { result in
             
             var imageCached = manager.cache.imageCachedType(forKey: url.cacheKey, processorIdentifier: p.identifier)
             var originalCached = manager.cache.imageCachedType(forKey: url.cacheKey)
@@ -303,7 +303,7 @@ class KingfisherManagerTests: XCTestCase {
 
         let p = SimpleProcessor()
         let options: KingfisherOptionsInfo = [.processor(p), .waitForCache]
-        manager.downloadAndCacheImage(with: url, forKey: url.cacheKey, options: options) {
+        manager.loadAndCacheImage(source: .network(url), options: options) {
             result in
             var imageCached = self.manager.cache.imageCachedType(forKey: url.cacheKey, processorIdentifier: p.identifier)
             var originalCached = self.manager.cache.imageCachedType(forKey: url.cacheKey)