RP8*_*P89 2 caching imageview ios swift kingfisher
我正在使用 Kingfisher 来加载来自 Url 的图像的图像视图。有时,相同的网址会更新为新图像。所以我使用下面的代码来加载图像视图,
profileImage.kf.setImage(with: profileUrl, placeholder: #imageLiteral(resourceName: "profile_1"), options: [.fromMemoryCacheOrRefresh], progressBlock: nil, completionHandler: nil)
Run Code Online (Sandbox Code Playgroud)
但图像没有得到更新。仅显示旧图像。为什么会出现这种情况?Kingfisher 文档中指出,“fromMemoryCacheOrRefresh 可用于在同一 url 后面显示可更改的图像,同时避免一次又一次下载”
Kingfisher 不支持服务器缓存机制。它只是使用整个 URL 作为本地缓存键。只要您使用相同的 URL,您就会从缓存中获取相同的图像(如果已缓存)。
因此,如果您的服务器在同一 URL 下提供不同的图像,我们建议您要求您的服务器向该 URL 添加不同版本的查询。这些 URL:“ https://example.com/image.png?v=1 ”和“ https://example.com/image.png?v=2 ”代表 Kingfisher 中的不同图像,并且可以很好地工作。同时,访问“ https://example.com/image.png?v=2 ”将导航到“ https://example.com/image.png ”数据,以实现大多数服务器的实现。
您可以在此页面上找到更多信息: