Search code examples
iosswiftcachingimageviewkingfisher

Show updated images in the same url using Kingfisher ios


I am using Kingfisher for loading image view with images from Url. Sometimes, the same url will updated with new image. So I am using below code to load the imageview,

profileImage.kf.setImage(with: profileUrl, placeholder: #imageLiteral(resourceName: "profile_1"), options: [.fromMemoryCacheOrRefresh], progressBlock: nil, completionHandler: nil)

But the image is not getting updated. Only the old image is showing. Why this happens ? In Kingfisher documentation, it is stated that, " fromMemoryCacheOrRefresh can be used to display changeable image behind same url, while avoiding download it again and again "


Solution

  • Kingfisher does not support server cache mechanism. It just uses the whole URL as the local cache key. As long as you use the same URL, you will get the same image from the cache (if it was cached).

    So, if your server provides different images under the same URL, we suggest you to ask your server to add a query to the URL for different versions. These URLs: "https://example.com/image.png?v=1" and "https://example.com/image.png?v=2" represent different images in Kingfisher and it could work well. At the same time, access to the "https://example.com/image.png?v=2" would navigate you to the "https://example.com/image.png" data for most implementation of the server.

    You can find more information on this page:

    https://github.com/onevcat/Kingfisher/wiki/FAQ#does-kingfisher-support-server-cache-tags-like-e-tag-or-last-modified