Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove an image from Nuke for Swift cache

I have been trying out Nuke framework for Image caching, from https://github.com/kean/Nuke, across the document I couldn't figure out how to remove an image from cache (both disk and memory), I could find a method from Cache class "removeAll" to remove images from cache , but I have two questions:

  1. How to remove single image?
  2. How to remove all images from disk as well as memory cache?

I haven't tried anything I am trying to check the documents before trying , so down voting because I don't have attached code isn't fare.

like image 611
vishal dharankar Avatar asked Jul 18 '17 14:07

vishal dharankar


1 Answers

To store unprocessed image data, Nuke uses a URLCache instance. So you have to call removeAllCachedResponses() of an appropriate URLCache instance.

As a result, you can clear image stored in disk as below codes if you use the shared instance of Nuke as mentioned by Sergey Di on the comment

Nuke.Cache.shared.removeAll()
Nuke.DataLoader.sharedUrlCache.removeAllCachedResponses()

If you use a custom shared ImagePipeline, it's a bit complicated but you can do like this code

(ImagePipeline.shared.configuration.dataLoader as? DataLoader)?.session.configuration.urlCache?.removeAllCachedResponses()

I hope my answer would help you.

like image 170
scenee Avatar answered Nov 15 '22 01:11

scenee