NSURLCache does not clear stored responses in iOS8 NSURLCache does not clear stored responses in iOS8 objective-c objective-c

NSURLCache does not clear stored responses in iOS8


NSURLCache is broken on iOS 8.0.x - it never purges the cache at all, so it grows without limit. See http://blog.airsource.co.uk/2014/10/11/nsurlcache-ios8-broken/ for a detailed investigation. Cache purging is fixed in the 8.1 betas - but removeCachedResponseForRequest: is not.

removeCachedResponsesSinceDate: does appear to work on iOS 8.0 - an API that was added for 8.0, but hasn't made it to the docs yet (it is in the API diffs). I am unclear what use it is to anyone - surely what you normally want to do is remove cached responses before a particular date.

removeAllCachedResponses works as well - but that's a real sledgehammer solution.


I got a sufficient result reseting the cached response for a specific URL, changing the cache control to something that would never be returned like a "max-age=0" in the header. Look here


Whenever any API call is generated, That response is saved in the cache. You are able to find that folder in your documents directory, a folder with named cachedb is created which contains a list of responses. It can be a major concern related to security. With any third-party tool, someone can have access to that information.

Below is the way I have solved this issue :

NSURLCache *cache = [[NSURLCache alloc] initWithMemoryCapacity:0 * 1024 * 1024 diskCapacity:0 * 1024 * 1024 diskPath:nil];[NSURLCache setSharedURLCache:cache];

I have allocated 0 memory space to the cache. so no data will be stored in Cache memory.