翠鸟库从缓存中删除图像

时间:2019-04-05 06:31:37

标签: swift caching kingfisher

目前,我正在从迅捷的Kingfisher库中加载图像,例如:

   if imageURL != nil {
        let imageConvertedUrl = URL(string: imageURL!)

        photo.kf.setImage(with: imageConvertedUrl, options: [.diskCacheExpiration(.days(3)), .memoryCacheExpiration(.days(3))]) { result in
            // `result` is either a `.success(RetrieveImageResult)` or a `.failure(KingfisherError)`
            switch result {
            case .success(let value):
                self.spinnerView.isHidden = true
                print(value.cacheType)

            case .failure(let error):
                print(error) // The error happens
                self.spinnerView.isHidden = false
            }
        }
    }

我可以关闭互联网,重新启动应用程序,并从缓存中加载图像而不会遇到麻烦。但是,几分钟后,如果我在没有Internet的情况下重新打开图像,将无法加载该图像,并且会遇到错误消息:

Internet connection appears to be offline., NSErrorFailingURLStringKey=

我不确定为什么不从缓存中加载图像,因为我将.diskCacheExpiration设置为3天,因此我认为它最多可以从缓存中加载3天。

0 个答案:

没有答案