当服务器上的图像文件更改时,我的应用程序中的 SDWebImage 缓存图像会发生什么情况? [英] What happens to SDWebImage Cached Images in my app when the image file on the server changes?

查看:23
本文介绍了当服务器上的图像文件更改时,我的应用程序中的 SDWebImage 缓存图像会发生什么情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SDWebImage 库在我的应用中缓存网络图像:

I am using the SDWebImage library to cache web images in my app:

https://github.com/rs/SDWebImage/blob/master/README.md

当前使用情况:

[imageView setImageWithURL:[NSURL URLWithString:profilePictureUrl] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

我的问题是,一旦图像被缓存,几天后服务器上的图像文件又用新图像更新,会发生什么?

My question is what happens once the image has been cached and then a couple of days later that image file on the server has been updated with a new image?

目前我的应用程序仍在显示缓存的图像.

At the moment my application is still displaying the cached image.

我在任何有关设置缓存超时或识别文件大小已更改的文档中都看不到.

I can't see in any of the documentation on setting a cache timeout or something that recognises that the file size has changed.

如果有人有使用这个特定库的经验,那么任何帮助将不胜感激.

If anyone has experience using this particular library then any help would be greatly appreciated.

提前致谢.

推荐答案

我查看了源代码.它像这样处理 setImageWithURL 方法:

I had a look at the source code. It processes the setImageWithURL method like this:

  1. 询问内存缓存是否有图像,如果有则返回图像并且不再继续
  2. 询问磁盘缓存是否有图像,如果有则返回图像并且不再继续
  3. 尝试下载图像,成功返回图像,否则保留占位符图像

没有发送请求来询问远程服务器是否有新版本,而磁盘上有旧版本,例如使用 ETags.

There is no request sent to ask the remote server if there is a new version while there is something old on disk, like using ETags of the HTTP protocol.

深入挖掘缓存时间在 SDImageCache.m

static NSInteger cacheMaxCacheAge = 60*60*24*7; // 1 week

它不能用 setter 改变.

it cannot be changed with a setter.

所以只要缓存中的图像有效,SDWebImage 库就不会下载任何新的东西.一周后,它会下载您更改后的图片.

So as long as the image in the cache is valid the SDWebImage lib won't download anything new. After a week it'll download your changed image.

这篇关于当服务器上的图像文件更改时,我的应用程序中的 SDWebImage 缓存图像会发生什么情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆