Clear NSURLConnection cache
Asked Answered
C

5

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.

Crisscross answered 26/10, 2011 at 20:54 Comment(1)
see [this][1] [1]: #405651Adowa
B
63

You can clear the cache explicitly using:

obj-c

[[NSURLCache sharedURLCache] removeAllCachedResponses];

swift

 URLCache.shared.removeAllCachedResponses()
Bushcraft answered 12/2, 2013 at 12:18 Comment(0)
E
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.

Evzone answered 26/10, 2011 at 20:59 Comment(2)
What does this have to do with the question?Amphistylar
Clearly this is a better way to use (or not use) a cache than removing all cached responses, so this has a lot to do with the question don't you think?Damnatory
D
2

Add one random number at the end of file name

Like abc.pdf?rand=10023

Diacritical answered 22/1, 2013 at 11:23 Comment(0)
S
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

Superphosphate answered 13/7, 2014 at 13:28 Comment(0)
S
-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.

Subversive answered 4/3, 2012 at 6:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.