如何使特定网址的iOS缓存无效? [英] How do I invalidate iOS's cache for a particular URL?

查看:84
本文介绍了如何使特定网址的iOS缓存无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用NSURLSession的默认缓存,如何使特定URL的缓存无效?

Using NSURLSession's default caching, how do I invalidate the cache for a particular URL?

我注意到NSURLCacheremoveCachedResponseForRequest:方法,但这需要一个NSURLRequest对象,对于原始请求我没有.创建它们时是否需要存储它们,以便可以将它们传递回removeCachedResponseForRequest:,还是可以仅创建一个具有适当URL的新URL,即使没有该URL,也可以用作该URL的等效项.标题字段和原始属性相同吗?

I note NSURLCache's removeCachedResponseForRequest: method, but that takes an NSURLRequest object, which I don't have for the original request. Do I need to store those as I create them so I can then pass them back into removeCachedResponseForRequest: or can I just create a new one with the appropriate URL which will then serve as equivalent for the purpose, even if it doesn't have the same header fields and other properties as the original?

推荐答案

该解决方案不是使现有URL的缓存无效,而是进行设置:

The solution turns out not to be invalidating the cache for an existing URL, but to set:

request.cachePolicy = NSURLRequestReloadIgnoringLocalCacheData;

下一次请求资源时,您知道该资源无效.有一些选项可以仅忽略本地缓存,也可以请求上游代理也忽略其缓存.参见

When you make the next request for the resource you know to be invalid. There are options to ignore the local cache only, or to request that upstream proxies ignore their caches too. See the NSURLRequest/NSMutableURLRequest documentation for details.

这篇关于如何使特定网址的iOS缓存无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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