How to remove an image from Nuke for Swift cache
Asked Answered
C

2

6

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?
Carabiniere answered 18/7, 2017 at 14:22 Comment(3)
If you are pretty sure that there is no documentation about this issue, I would suggest to report it as an issue on the github repo.Weiner
github.com/kean/Nuke/issues/128Hyphenate
So eventually they allow us manipulate Cache through URLCache but its not straight , not good for a frameworkCarabiniere
D
2

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.

Diegodiehard answered 26/12, 2018 at 8:50 Comment(2)
It gives me an error: Module 'Nuke' has no member named 'Cache'Confessedly
@Confessedly Try Nuke.ImageCacheOverabound
A
0

try this!

Nuke.ImagePipeline.shared.cache.removeAll()
Adagio answered 18/7 at 9:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.