Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

ios - 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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()
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...