我现在正在做一个iPhone应用程序项目,它使用cachePolicy:NSURLCacheStorageNotAllowed (我使用的是iOS7)使用NSURLRequests实现一些连接。
但似乎响应仍然被缓存,并且我得到了相同URL调用的旧响应。尽管将缓存策略设置为"cachePolicy:NSURLCacheStorageNotAllowed".
为什么它仍然缓存响应?这个问题在最新版本中仍然存在吗?
发布于 2014-07-13 15:44:47
缓存策略iOS7的正确枚举如下所述:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:downloadURL
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:60];如果你超过3G,一些提供商使用缓存,即使你在你的缓存中禁用它,所以如果缓存策略不起作用,那么设置http报头字段NSMutableURLRequest -control为no-cache。
[request setValue:@"no-cache" forHTTPHeaderField:@"cache-control"];这里的枚举列表检查您的头NSURLRequest.h是否有正确的最新枚举:)
enum
{
NSURLRequestUseProtocolCachePolicy = 0,
NSURLRequestReloadIgnoringLocalCacheData = 1,
NSURLRequestReloadIgnoringLocalAndRemoteCacheData = 4, // Unimplemented
NSURLRequestReloadIgnoringCacheData = NSURLRequestReloadIgnoringLocalCacheData,
NSURLRequestReturnCacheDataElseLoad = 2,
NSURLRequestReturnCacheDataDontLoad = 3,
NSURLRequestReloadRevalidatingCacheData = 5, // Unimplemented
};
typedef NSUInteger NSURLRequestCachePolicy;发布于 2016-09-07 20:31:21
非缓存请求的正确答案应该是NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:downloadURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];,因为它是未实现的。
https://stackoverflow.com/questions/22121947
复制相似问题