2
0
Эх сурвалжийг харах

Merge pull request #257 from wedrive-rb26/fix-image-flicker

Disable background decoding for images from the in memory cache.
Wei Wang 10 жил өмнө
parent
commit
4cf32129c3

+ 2 - 12
Sources/ImageCache.swift

@@ -279,18 +279,8 @@ extension ImageCache {
         let options = options ?? KingfisherEmptyOptionsInfo
         
         if let image = self.retrieveImageInMemoryCacheForKey(key) {
-            //Found image in memory cache.
-            if options.backgroundDecode {
-                dispatch_async(self.processQueue, { () -> Void in
-                    let result = image.kf_decodedImage(scale: options.scaleFactor)
-                    dispatch_async_safely_to_queue(options.callbackDispatchQueue, { () -> Void in
-                        completionHandler(result, .Memory)
-                    })
-                })
-            } else {
-                dispatch_async_safely_to_queue(options.callbackDispatchQueue, { () -> Void in
-                    completionHandler(image, .Memory)
-                })
+            dispatch_async_safely_to_queue(options.callbackDispatchQueue) { () -> Void in
+                completionHandler(image, .Memory)
             }
         } else {
             var sSelf: ImageCache! = self

+ 15 - 1
Tests/KingfisherTests/ImageCacheTests.swift

@@ -152,7 +152,21 @@ class ImageCacheTests: XCTestCase {
         
         waitForExpectationsWithTimeout(5, handler: nil)
     }
-    
+
+    func testCachedImageIsFetchedSyncronouslyFromTheMemoryCache() {
+        cache.storeImage(testImage, forKey: testKeys[0], toDisk: false) { () -> () in
+            // do nothing
+        }
+
+        var foundImage: Image?
+
+        cache.retrieveImageForKey(testKeys[0], options: [.BackgroundDecode]) { (image, type) -> () in
+            foundImage = image
+        }
+
+        XCTAssertEqual(testImage, foundImage, "should have found the image immediately")
+    }
+
     func testIsImageCachedForKey() {
         let expectation = self.expectationWithDescription("wait for caching image")