使用 Kingfisher 如何缓存保持相同 URL 的新图像?

Using Kingfisher how can I cache a new image which has kept the same URL?

我知道有一个强制刷新的选项,但我正在寻找一个仍然可以缓存图像而不必每次都从网络加载图像的解决方案。

目前,如果我尝试设置具有相同 URL 的新图像,它只会显示已缓存的先前图像,而不会覆盖新的 url。

找到了我自己的解决方案,尽管它可能不是最好的方法。

首先,当我更新图像时,我更改了一个 public 变量来反映这一点。然后我检查图像是否被缓存,如果是则将其删除。

import Kingfisher

if self.imageHasUpdated {
      if ImageCache.default.isImageCached(forKey: image.absoluteString).cached {
               print("Image is cached")
               ImageCache.default.removeImage(forKey: image.absoluteString)
               self.imageHasUpdated = false
      }
}

终于正常更新图片了。

imageView.kf.setImage(with: imageURL, placeholder: nil, options: nil)