开发者

Avoiding cached data with NSURLRequest

I had this problem while developing an app where the request was a simple URL and the response returned XML.

I used the [NSURLRequest sendsynchronousrequest] and the request header Cache-Control had default max-age value of 81769 by default. Because of this, the response i got was not the latest XML but an old XML. Safari and IE returned an old XML but Chrome and Firefox returned the updated latest XML.

I guessed the reason IE and Safari returned the old XML was because the Cache-Control max age was 817开发者_JS百科69 whereas the same header when inspected in chrome or Firefox returned 0.

So i manually set the max-age value as 0 for the header field and got the latest XML as response.

I want to know if this is the best solution or is there any other reliable method to get the latest response.


You want to look at the set of NSURLRequestCachePolicy enum values.

Specifically, you can create an NSURLRequest object using the +[NSURLRequest requestWithURL:cachePolicy:timeoutInterval:] method and specify NSURLRequestReloadIgnoringLocalCacheData or something similar for the cache policy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜