Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear all cached images loaded from SDWebImage?

I have all images loaded on my app via SDWebImage. The downloading and caching works great, but I wanted to make a button that can clear all cached images in the entire app.

I have a "Clear Cache" button as a UIButton on one of my tab bar views. How can I make it so when this button is tapped, all the cached images are removed and need to be re-downloaded?

Using Swift.

Thank you!

like image 645
Miles Avatar asked Oct 05 '16 18:10

Miles


People also ask

How to clear “cache image and file”?

How to clear "cache image and file" at your browser! To day, We updated some special funtion at our website!!! Please clear "cache image and file" at your browser before login to our website. Press the keys [Ctrl] , [Shift] and [Del]. Be sure you press all the keys at once. Or go to that link chrome://settings/clearBrowserData

What happened to the sdwebimage library?

In order to keep SDWebImage focused and limited to the core features, but also allow extensibility and custom behaviors, during the 5.0 refactoring we focused on modularizing the library. As such, we have moved/built new modules to SDWebImage org.

What's new in sdwebimage 5?

Support extendable coder plugins for new image formats like BPG, AVIF. And vector format like PDF, SVG. See all the list in Image coder plugin List In order to keep SDWebImage focused and limited to the core features, but also allow extensibility and custom behaviors, during the 5.0 refactoring we focused on modularizing the library.

How do I clear the cache on my browser?

Press the keys [Ctrl] , [Shift] and [del] on your Keyboard. A new window opens, where you can setup the options to delete the cache. Select the period "since installation", to empty the whole browser cache. Check the Option "Images and Files in Cache".


2 Answers

If you want to completely clear the cache do the following:

Obj-c:

- (IBAction)clearCache:(id)sender {
    [[SDImageCache sharedImageCache]clearMemory];
    [[SDImageCache sharedImageCache]clearDisk];
}

Swift 5

SDImageCache.shared.clearMemory()
SDImageCache.shared.clearDisk()

Swift 3.0

@IBAction func clearCache(sender: UIButton) {
    SDImageCache.shared().clearMemory()
    SDImageCache.shared().clearDisk()
}
like image 199
guidev Avatar answered Oct 12 '22 16:10

guidev


Try this:

@IBAction func actClearCache(sender:AnyObject) {

   let objCache = SDImageCache.sharedImageCache()
   objCache.clearMemory()
   objCache.cleanDisk()

}
like image 2
Bista Avatar answered Oct 12 '22 15:10

Bista