Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 291
moeseth Avatar asked Oct 26 '11 20:10

moeseth


People also ask

What is NSURLConnection?

An NSURLConnection object lets you load the contents of a URL by providing a URL request object. The interface for NSURLConnection is sparse, providing only the controls to start and cancel asynchronous loads of a URL request. You perform most of your configuration on the URL request object itself.

What is cache policy in Swift?

The constants used to specify interaction with the cached responses. iOS 2.0+ iPadOS 2.0+ macOS 10.2+ Mac Catalyst 13.0+ tvOS 9.0+ watchOS 2.0+

What is NSURLCache?

The NSURLCache class implements the caching of responses to URL load requests, by mapping NSURLRequest objects to NSCachedURLResponse objects. It provides a composite in-memory and on-disk cache, and lets you manipulate the sizes of both the in-memory and on-disk portions.


2 Answers

You can clear the cache explicitly using:

obj-c

[[NSURLCache sharedURLCache] removeAllCachedResponses]; 

swift

 URLCache.shared.removeAllCachedResponses() 
like image 50
Ben-G Avatar answered Sep 28 '22 02:09

Ben-G


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.

like image 40
Robin Summerhill Avatar answered Sep 28 '22 00:09

Robin Summerhill