Clear NSURLConnection cache

2019-04-03 04:01发布

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.

5条回答
Bombasti
2楼-- · 2019-04-03 04:24

Add one random number at the end of file name

Like abc.pdf?rand=10023

查看更多
做个烂人
3楼-- · 2019-04-03 04:26

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.

查看更多
趁早两清
4楼-- · 2019-04-03 04:26

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.

查看更多
▲ chillily
5楼-- · 2019-04-03 04:30

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

TLS Session Cache

查看更多
SAY GOODBYE
6楼-- · 2019-04-03 04:42

You can clear the cache explicitly using:

obj-c

[[NSURLCache sharedURLCache] removeAllCachedResponses];

swift

 URLCache.shared.removeAllCachedResponses()
查看更多
登录 后发表回答