Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
set url without query as cachekey
Browse files Browse the repository at this point in the history
  • Loading branch information
Suric zhang committed Dec 16, 2016
1 parent 7e9e309 commit bc5cbab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
14 changes: 12 additions & 2 deletions PhotoBrowser/Photo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public struct Photo {
if image != nil {
return image
} else if let photoUrl = photoUrl {
let image = KingfisherManager.shared.cache.retrieveImageInMemoryCache(forKey: photoUrl.absoluteString)
return image ?? KingfisherManager.shared.cache.retrieveImageInDiskCache(forKey: photoUrl.absoluteString)
let image = KingfisherManager.shared.cache.retrieveImageInMemoryCache(forKey: photoUrl.kfCacheKey)
return image ?? KingfisherManager.shared.cache.retrieveImageInDiskCache(forKey: photoUrl.kfCacheKey)
}
return nil
}
Expand All @@ -65,3 +65,13 @@ public struct Photo {

}
}

extension URL {
var kfCacheKey: String {
var photoCacheKey = absoluteString
if let query = query {
photoCacheKey = absoluteString.replacingOccurrences(of: query, with: "")
}
return photoCacheKey
}
}
4 changes: 3 additions & 1 deletion PhotoBrowser/PhotoPreviewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ class PhotoPreviewController: UIViewController {
newWaitingView.center = view.center
view.addSubview(newWaitingView)
}
imageView.kf.setImage(with: photoUrl, placeholder: photo.localThumbnailPhoto(), options: nil, progressBlock: { (receivedSize, totalSize) -> () in

let resource = ImageResource(downloadURL: photoUrl, cacheKey: photoUrl.kfCacheKey)
imageView.kf.setImage(with: resource, placeholder: photo.localThumbnailPhoto(), options: nil, progressBlock: { (receivedSize, totalSize) -> () in
let progress = CGFloat(receivedSize) / CGFloat(totalSize)
if let waitingView = self.waitingView {
waitingView.progress = progress
Expand Down
2 changes: 1 addition & 1 deletion PhotoBrowserDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ViewController: UIViewController {
extension ViewController {
func displayPhotoBrowser() {
let thumbnail1 = UIImage.init(named: "thumbnail1")
let photoUrl1 = URL.init(string: "https://pic4.zhimg.com/453d7ebcdb0c4494e60fa07d09a83a83_r.jpeg")
let photoUrl1 = URL.init(string: "https://www.teambition.com/api/works/575d0bbf93e0f8860d73d88e/download/IMG_0005.JPG.jpeg?signature=eyJhbGciOiJIUzI1NiJ9.eyJfd29ya0lkIjoiNTc1ZDBiYmY5M2UwZjg4NjBkNzNkODhlIiwiZmlsZUtleSI6IjExMGg2MzRhOTg3MDQ5MDJmNDY1MmJhZTYzYjI1MTQyZTUyMSIsIl91c2VySWQiOiI1MmE2Y2MyZGVmNjZiYzk4MGMwMDAzMTIiLCJleHAiOjE0ODIwNjA0ODgsInN0b3JhZ2UiOiJzdHJpa2VyLWh6In0.czjEgDdAKqqOm8fK8lDOiE7wA_5H48bh6phlomGQqWo")
let thumbnail2 = UIImage.init(named: "thumbnail2")
let photoUrl2 = URL.init(string: "https://pic1.zhimg.com/0f70807392a9f62528b00ec434f5519c_b.png")
let thumbnail3 = UIImage.init(named: "thumbnail3")
Expand Down

0 comments on commit bc5cbab

Please sign in to comment.