Skip to content

Commit

Permalink
Merge pull request onevcat#257 from wedrive-rb26/fix-image-flicker
Browse files Browse the repository at this point in the history
Disable background decoding for images from the in memory cache.
onevcat committed Feb 29, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents a453804 + 9b70fa8 commit 4cf3212
Showing 2 changed files with 17 additions and 13 deletions.
14 changes: 2 additions & 12 deletions Sources/ImageCache.swift
Original file line number Diff line number Diff line change
@@ -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
16 changes: 15 additions & 1 deletion Tests/KingfisherTests/ImageCacheTests.swift
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 4cf3212

Please sign in to comment.