gpt4 book ai didi

swift - 如何使用sdwebimage永久保存图像?

转载 作者:行者123 更新时间:2023-11-30 11:47:56 25 4
gpt4 key购买 nike

我是 swift 的新人。我有一个问题如何将图像从 url 保存到永久缓存中。由于 URL 仅保留 30 分钟,并在 30 分钟后过期,因此我使用 sdwebimage 并将图像保存在磁盘和内存缓存中。我的代码如下所示。并且运行良好。问题是有时由于未知问题而无法加载图像。我猜测图像不会永久保存在缓存中。这只是我的猜测。所以,我想保存图像永久缓存。我怎样才能做到这一点?或者有谁知道为什么会出现这种症状?

我的代码:

cell.imageView.sd_setImage(with: URL(string: url), placeholderImage: nil)

最佳答案

我想当您已经保存它时应该不会发生这种情况,也许您正在项目中的某个地方刷新它。

条件1:您可能设置了刷新缓存代码。

imgView.sd_setImage(with: URL(string: yourString!), placeholderImage:UIImage(named: "placeholder_icon"), options: .refreshCached)

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

条件2:您是否设置了刷新缓存时间,例如

SDImageCache.shared().config.maxCacheAge = 60 * 60 * 24;

If your case is not from above two conditions, I am eager to know the answer.

关于swift - 如何使用sdwebimage永久保存图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48623103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com