2
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)
    }

I can get the image in the Console, but I can not find them in the Caches.

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

image description here

DimaSan
  • 12,264
  • 11
  • 65
  • 75
duguyihou
  • 33
  • 3
  • 9

2 Answers2

13

The downloader (ImageDownloader) has nothing to do with cache. If you want to download and cache (as well as retrieve the cached images later), you should use the manager method: KingfisherManager.shared.retrieveImage instead of downloader standalone.

onevcat
  • 4,591
  • 1
  • 25
  • 31
0

See this extract from the documentation:

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

Check what the result of cacheType is. It might not be stored in a disk cache.

Do this:

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

Paste output.

toast
  • 1,860
  • 2
  • 26
  • 49
  • Thanks for your replay. – duguyihou Oct 18 '16 at 02:12
  • `for url in status.storedPicURLS! { group.enter() KingfisherManager.shared.retrieveImage(with: url, options: nil, progressBlock: nil, completionHandler: { (_, _, _, _) in group.leave() }) } } group.notify(queue: .main) { finished(list, nil) } ` – duguyihou Oct 18 '16 at 02:13
  • Use the function I modified in my answer, then print(cacheType) – toast Oct 18 '16 at 02:31
  • Optional(http://ww3.sinaimg.cn/thumbnail/c5ff030ejw1f8w502k1pej21bs0jw10y.jpg) Optional(http://ww4.sinaimg.cn/thumbnail/c5ff030ejw1f8w5039j6fj21a408saf5.jpg) Optional(http://ww3.sinaimg.cn/thumbnail/aa1f155cjw1f8vgtyyt9jj20bn00xt8k.jpg) Optional(http://ww2.sinaimg.cn/thumbnail/a841894bgw1f8vtfjc2dyj20zk0qo10s.jpg) Optional(http://ww2.sinaimg.cn/thumbnail/c5ff030ejw1f8v10krrs7j20x40lcadn.jpg) Optional(http://ww2.sinaimg.cn/thumbnail/6e1068adjw1f8v5xnxwmbj20l20cy759.jpg) I got them in console, but still find nothing in Caches. How should I do with cacheType? – duguyihou Oct 18 '16 at 02:50
  • I updated my answer to print cacheType. Update that section of your code and paste the results. – toast Oct 18 '16 at 03:31
  • Optional(731 bytes), from cache: Optional(http://ww4.sinaimg.cn/thumbnail/c5ff030ejw1f8w503qp2nj215g02cace.jpg) Optional(714 bytes), from cache: Optional(http://ww3.sinaimg.cn/thumbnail/aa1f155cjw1f8vgtyyt9jj20bn00xt8k.jpg) Optional(1195 bytes), from cache: Optional(http://ww4.sinaimg.cn/thumbnail/c5ff030ejw1f8w5039j6fj21a408saf5.jpg) – duguyihou Oct 18 '16 at 04:03
  • '/// Completion block of downloader. public typealias ImageDownloaderCompletionHandler = ((Image?, NSError?, URL?, Data?) -> ())' The third paramer in the block is URL?, no CacheType. – duguyihou Oct 18 '16 at 04:07
  • ``` for url in status.storedPicURLS! { group.enter() KingfisherManager.shared.retrieveImage(with: url, options: nil, progressBlock: nil, completionHandler: { (_, _, _, _) in group.leave() }) } } group.notify(queue: .main) { finished(list, nil) } ``` – duguyihou Oct 18 '16 at 07:41