0

I am using HanekeSwift to download an image from URL and set it in the UIImage.

I am doing it like .hnk_setImageFromURL()

The image URL gets updated with new image frequently and I need to download the new image. But as the image is already available in cache, the image is taken from the cache and not from the url fetch. In order to solve this I tried to remove cache entry for this key(i.e URL) using Shared.imageCache.remove(key: ).

Even after doing this the image is fetched from the cache and I do not see any network calls. Looks like the remove(key:) function is not working as expected.

Help me to find a solution for this issue.

Badal Shah
  • 7,541
  • 2
  • 30
  • 65
Jithesh
  • 51
  • 5
  • The url was not returning contentType image. As a result the image might have not been added in the imageCache. But I was trying to remove it from imageCache. After fixing the url response to return contentType image the problem is resolved. – Jithesh Feb 15 '16 at 03:36

1 Answers1

1

If you are cacheing image using image.hnk_setImageFromURL(URL) in that case you have to remove all cache for image instance ,but if you are cache image using with key value pair you can remove cache using it key.

example

If i cache image like

let imageCache = Shared.imageCache
imageview.hnk_setImageFromURL(URL) 

in above case you can remove cache using imageCache.removeAll() but if you are cache image like

imageview.hnk_setImage(UIImage(), key:"image") in that case you can remove using imageCache.remove(key: "image")

you can also cache image using imageCache.set(value: UIImage(named:""), key: "image") and remove cache using imageCache.remove(key: "image")

Donal
  • 6,082
  • 2
  • 19
  • 30
  • I don't think you (should) have to set a custom key to be able to remove images set from a URL. NetworkFetcher make the cache key from url.absoluteString so you should be able to remove the image using that as the key. I do still have that failing but I consider it a bug and not an intended limitation. – Martin Westin Nov 07 '18 at 14:38