Nsurlcache Does Not Clear Stored Responses in iOS8

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.

NSURLCache's removeCachedResponseForRequest has no effect

Assuming you are on iOS 8, removeCachedResponseForRequest: does not work.

See http://blog.airsource.co.uk/2014/10/13/nsurlcache-ios8-broken-2/

Images are not removed from disk after clearing cache AFNetworking

See follows:

  1. AFAutoPurgingImageCache *imageCache = [AFImageDownloader defaultInstance].imageCache; The imageCache is stored in the memory, it is useless to do [imageCache removeAllImages];
  2. You just need to do [[AFImageDownloader defaultURLCache] removeAllCachedResponses];. It is the only API that apple offers to clear the URLCache.
  3. You find the fsCachedData is not removed when you call removeAllCachedResponses. It is because apple has its own mechanism to clear the disk data. Maybe it will clear the disk data in every 7 days as i searched, but i can not make sure.
  4. I think it is interesting to see how the others use fsCachedData. Should I clear the fsCachedData folder myself?
  5. I hope it will help u.

Prevent caching in NSURLSession for iOS Simulator

I had a similar issue and I was able to fix this by setting the properties- URLCache and requestCachePolicy on NSURLSessionConfiguration to nil and NSURLRequestReloadIgnoringCacheData respectively.

Also, you can try setting the cachePolicy property on NSMutableURLRequest to NSURLRequestReloadIgnoringCacheData.

How do I invalidate iOS's cache for a particular URL?

The solution turns out not to be invalidating the cache for an existing URL, but to set:

request.cachePolicy = NSURLRequestReloadIgnoringLocalCacheData;

When you make the next request for the resource you know to be invalid. There are options to ignore the local cache only, or to request that upstream proxies ignore their caches too. See the NSURLRequest/NSMutableURLRequest documentation for details.



Related Topics



Leave a reply



Submit