vardha
vardha

Reputation: 414

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 81769 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.

Upvotes: 1

Views: 468

Answers (1)

Aidan Steele
Aidan Steele

Reputation: 11330

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.

Upvotes: 1

Related Questions