Clear NSURLConnection cache

戏子无情 提交于 2019-12-04 15:18:48

问题


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.


回答1:


You can clear the cache explicitly using:

obj-c

[[NSURLCache sharedURLCache] removeAllCachedResponses];

swift

 URLCache.shared.removeAllCachedResponses()



回答2:


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.




回答3:


Add one random number at the end of file name

Like abc.pdf?rand=10023




回答4:


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

TLS Session Cache




回答5:


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.



来源:https://stackoverflow.com/questions/7908815/clear-nsurlconnection-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!