New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
清除图片的缓存 #2204
Comments
复盘发现,是因为app重启,丢失了所有processor的内容,导致缓存清理不掉。 |
这个场景,我个人现在的建议是,你可以为每个URL设置一个 var caches = [String: ImageCache]()
func imageCacheForURL(_ url: URL) -> ImageCache {
caches[url.absoluteString] ?? {
let c = ImageCache(name: url.absoluteString)
caches[url.absoluteString] = c
return c
}()
}
let imageView: UIImageView
imageView.kf.setImage(with: url, options: [.processor(processor1), .targetCache(imageCacheForURL(url))])
imageView.kf.setImage(with: url, options: [.processor(processor2), .targetCache(imageCacheForURL(url))])
// Later
imageCacheForURL(url).clearCache() |
感谢大佬提供的思路,看起来很简洁!祝您新年快乐,万事如意~发自我的 iPhone在 2024年2月4日,16:27,Wei Wang ***@***.***> 写道:
这个场景,我个人现在的建议是,你可以为每个URL设置一个 cache (伪代码,不一定正确):
var caches = [String: ImageCache]()
func imageCacheForURL(_ url: URL) -> ImageCache {
caches[url.absoluteString] ?? {
let c = ImageCache(name: url.absoluteString)
caches[url.absoluteString] = c
return c
}()
}
let imageView: UIImageView
imageView.kf.setImage(with: url, options: [.processor(processor1), .targetCache(imageCacheForURL(url))])
imageView.kf.setImage(with: url, options: [.processor(processor2), .targetCache(imageCacheForURL(url))])
// Later
imageCacheForURL(url).clearCache()
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check List
Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.
Issue Description
缓存清不掉
What
同一张《本地》(本地沙盒里,本地生成的)图片,多个imageview去展示,因为这些iv的大小不一样,结合downsample之后,他们缓存key也不一样。
用户可以修改本地图片,变化后,我需要清理掉所有【这张图片】的缓存,以便让用户看到最新的样子。
我看了源码,自己构建了相对应的缓存key(把所有可能出现的imageview的大小记录下来,无脑添加到后缀,构建缓存key,无脑调用mem和disk的清理方法),去清理,还是在某些场景下,莫名其妙的清不掉,非常影响用户体验。
只想要一个api可以清理掉【这张图片】的缓存,也就是说,不论是经过什么变换,缓存里有多少个不同变换的key,清理【这张图片】的所有缓存。
Reproduce
[The steps to reproduce this issue. What is the url you were trying to load, where did you put your code, etc.]
Other Comment
[Add anything else here]
The text was updated successfully, but these errors were encountered: