moeseth
moeseth

Reputation: 1945

Clear NSURLConnection cache

Is there a way to clear NSURLConnection cache?

I used that to download some strings but I keep getting the same strings even though I changed that from my server.

Upvotes: 28

Views: 20538

Answers (5)

Ben-G
Ben-G

Reputation: 5026

You can clear the cache explicitly using:

obj-c

[[NSURLCache sharedURLCache] removeAllCachedResponses];

swift

 URLCache.shared.removeAllCachedResponses()

Upvotes: 63

Hussain Mansoor
Hussain Mansoor

Reputation: 3134

Here's a way from official Apple pages that might help. Just read the short and informative answer in the link.

TLS Session Cache

Upvotes: 0

Bejoy
Bejoy

Reputation: 311

Add one random number at the end of file name

Like abc.pdf?rand=10023

Upvotes: 2

vikram mehta
vikram mehta

Reputation: 7

I had same issue, no matter what I do I will keep getting old data from web. I did a simple solution. I made a php script. This script reads the data . now I access this php script instead of the data file and I am good to go.

Upvotes: -4

Robin Summerhill
Robin Summerhill

Reputation: 13675

You specify cache policy when you create your NSURLRequest object. Set the cachePolicy property to NSURLRequestReloadIgnoringCacheData or use the initWithURL:cachePolicy:timeoutInterval: initializer. See documentation on cache policy.

Upvotes: 15

Related Questions