简体   繁体   English

使用SDWebImage和FirebaseStorageUI删除缓存URL

[英]Remove cache URL with SDWebImage and FirebaseStorageUI

I'm using FirebaseStorageUI to download images using Firebase in my iOS project. 我正在使用FirebaseStorageUI在我的iOS项目中使用FirebaseStorageUI下载图像。 Everything worked perfect, up to a point where there's no documentation about the issue I have. 一切工作都很完美,直到没有关于我遇到的问题的文档为止。

I usually clear SDWebImage's cache of one specific url using this: 我通常使用以下命令清除一个特定网址的SDWebImage缓存:

SDImageCache.shared().removeImage(forKey: "value", fromDisk: true, withCompletion: nil)

However, with Firebase there are only FIRStorageReference objects used to retrieve the images, therefore the only method I see to successfully accomplish what I want is to do this: 但是,在Firebase中,只有FIRStorageReference对象用于检索图像,因此,我看到要成功完成所需的唯一方法是执行以下操作:

ref.downloadURL { (url, error) in
    // code  
}

This is quite tedious work, given the fact that I already have a plethora of closures to handle only the interactions with Firebase. 考虑到我已经有很多闭包仅处理与Firebase的交互这一事实,这是非常繁琐的工作。 Is this the single way to clear the cache? 这是清除缓存的唯一方法吗?

I would suggest that you use Kingfisher instead. 我建议您改用翠鸟 It comes with an extension to UIImageView that simplifies downloading images from urls. 它带有UIImageView扩展,可简化从url下载图像。

let url = URL(string: "image_url")
imageView.kf.setImage(with: url)

To manually clear the image cache used by Kingfisher: 手动清除翠鸟使用的图像缓存:

ImageCache.default.clearDiskCache()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM