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.
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.
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+
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.
You can clear the cache explicitly using:
obj-c
[[NSURLCache sharedURLCache] removeAllCachedResponses];
swift
URLCache.shared.removeAllCachedResponses()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With