I made a button to clear my cache:
[[NSURLCache sharedURLCache]removeAllCachedResponses];
after this being done, I check the size of sharedURLCache:
NSInteger sizeInteger = [[NSURLCache sharedURLCache] currentDiskUsage];
float sizeInMB = sizeInteger / (1024.0f * 1024.0f);
the sizeInMB is 0.17, sometimes 0.13. Never 0.0. Why the removeAllCachedResponses doesn't make the sharedURLCache to ZERO ?
ps: in AppDelegate.m didFinishLaunchingWithOptions:
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:2 * 1024 * 1024
diskCapacity:20 * 1024 * 1024
diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
During pen test (security testing), I have got issue of caching url request/ response by iOS in cache.db.
I tried using
URLCache.shared.removeCachedResponse(for: URLRequest) and URLCache.shared.removeAllCachedResponses()
Both above API doesn't seems to be working just after getting response from API Call
Then got it working by putting following two line of code in didFinishLaunchingWithOptions in AppDelegate
// first remove all url cache from previous versions of app
URLCache.shared.removeAllCachedResponses()
// As we do not want to cache any request response so
// updated shared instance of url cache with custom url cache where
// memoryCapacity = 0, diskCapacity = 0 and diskPath = nil
URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
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