翠鸟缓存图像到磁盘

时间:2016-10-17 16:43:49

标签: ios uikit kingfisher

for url in status.storedPicURLS! {
            group.enter()
            print("\(status.storedPicURLS)")
            KingfisherManager.shared.downloader.downloadImage(with: url, options: nil, progressBlock: nil, completionHandler: { (image, _, _, _) in
                print(" \(image)")
                group.leave()
            })
        }
    }
    group.notify(queue: .main) {
        finished(list, nil)
    }

我可以在控制台中获取图像,但我无法在缓存中找到它们。

/Library/Developer/CoreSimulator/Devices/7AF33AA9-220E-4B54-9830-  AA94226C16E8/data/Containers/Data/Application/451F885E-1DFF-4E57-A0D7-B3DEC880DF8F/Library/Caches/

image description here

2 个答案:

答案 0 :(得分:9)

下载程序(ImageDownloader)与缓存无关。如果要下载和缓存(以及稍后检索缓存的图像),则应使用管理器方法:KingfisherManager.shared.retrieveImage而不是单独下载。

答案 1 :(得分:0)

请参阅文档中的摘录:

imageView.kf.setImage(with: url, completionHandler: { 
    (image, error, cacheType, imageUrl) in
    // image: Image? `nil` means failed
    // error: NSError? non-`nil` means failed
    // cacheType: CacheType
    //                  .none - Just downloaded
    //                  .memory - Got from memory cache
    //                  .disk - Got from memory Disk
    // imageUrl: URL of the image
})

https://github.com/onevcat/Kingfisher/wiki/Cheat-Sheet

检查cacheType的结果。它可能不存储在磁盘缓存中。

这样做:

        KingfisherManager.shared.downloader.downloadImage(with: url, options: nil, progressBlock: nil, completionHandler: {  (image, error, cacheType, imageUrl) in
            print("\(imageUrl), from cache: \(cacheType)")
            group.leave()
        })

粘贴输出。