我无法强制ImageDownloader正确使用ReturnCacheDataElseLoad(使用以前从缓存中下载的图片)
我在我的应用中使用的服务器返回标题下方:
headers {
"Cache-Control" = "public, max-age=600";
Connection = "keep-alive";
"Content-Type" = "image/jpeg";
Date = "Mon, 29 Feb 2016 13:25:22 GMT";
"Transfer-Encoding" = Identity;
"X-Powered-By" = Express;
}
ImageDownloader由下面描述的配置初始化:
let configuration = ImageDownloader.defaultURLSessionConfiguration()
// If we do not use image filters, it is advised by Alamofire to set the memory capacity of the NSURLCache to zero to avoid storing the same content in-memory twice.
configuration.URLCache?.memoryCapacity = 0
// Existing cache data should be used to satisfy a URL load request, regardless of its age or expiration date.
// However, if there is no existing data in the cache corresponding to a URL load request, the URL is loaded from the origin source
configuration.requestCachePolicy = .ReturnCacheDataElseLoad
问题是,当我在离线模式下重新打开应用程序10分钟后(由缓存控制标头中的服务器定义600秒)后,所有以前下载的图片都会消失。
我从这里尝试了各种解决方案(如此处所述:Alamofire - NSURLCache is not working?),但没有任何帮助。
编辑: 我刚刚观察到的另一件事(可能会影响上面的行为)是文件夹/ Library / Caches / {appname} / fsCachedData在某些时候被删除(系统未知?)