28

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
moeseth
  • 1,855
  • 5
  • 23
  • 47
  • 2
    see [this][1] [1]: http://stackoverflow.com/questions/405151/is-it-possible-to-prevent-an-nsurlrequest-from-caching-data-or-remove-cached-dat – aahsanali Oct 26 '11 at 21:04

5 Answers5

63

You can clear the cache explicitly using:

obj-c

[[NSURLCache sharedURLCache] removeAllCachedResponses];

swift

 URLCache.shared.removeAllCachedResponses()
hbk
  • 10,908
  • 11
  • 91
  • 124
Ben-G
  • 4,996
  • 27
  • 33
15

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.

Robin Summerhill
  • 13,695
  • 3
  • 41
  • 37
2

Add one random number at the end of file name

Like abc.pdf?rand=10023

P.J
  • 6,547
  • 9
  • 44
  • 74
Bejoy
  • 311
  • 2
  • 5
0

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

TLS Session Cache

Hussain Mansoor
  • 2,934
  • 2
  • 27
  • 40
-4

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.

ppaulojr
  • 3,579
  • 4
  • 29
  • 56