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

查看:119
本文介绍了当服务器上的图像文件发生变化时,我的应用程序中的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. li>
  4. 尝试下载图片,成功返回图片,否则保留占位符图片

  1. Ask the memory cache if the image is there, if yes return the image and don't go any further
  2. Ask the disk cache if the image is there, if yes return the image and don't go any further
  3. Try to download the image, return image on success else keep the placeholder image

没有发送请求远程服务器是否有新版本,而磁盘上有旧版本,例如使用 ETags HTTP协议。

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 中将挖掘时间更深一些设置为静态值

Digging a bit deeper the cache time is set to a static value in SDImageCache.m

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

使用setter无法更改。

it cannot be changed with a setter.

因此,只要缓存中的图像有效, SDWebImage lib就不会下载任何新内容。一周后它会下载你改变的图像。

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天全站免登陆