NSURLCache - Disk caching for GET request with parameters not working

微笑、不失礼 提交于 2019-12-03 20:08:34

The problem appeared to be with not specifying memory capacity, if you specify the memory capacity as follows,

Here I am specifying memory capacity to be 1 MB of size

[[NSURLCache alloc] initWithMemoryCapacity:1*1024*1024 diskCapacity:sz diskPath:nil];

it will work, it appears to me as if the memory capacity is needed no matter, how small the capacity is but cannot be empty. Then you will be able to extract stored cached as follows,

NSCachedURLResponse *cachedResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:request];
response = cachedResponse.response;
data = cachedResponse.data;

Finally I overrided NSURLCache to be able to achieve what I was looking for:

  1. GET requests (with parameters) being cached to Disk
  2. Requests going to cache while "Cache-Control max-age" value says it is not expired, and going to the server again after expiration, storing the new response and starting the expiration time over
  3. If offline, always return the response (if it exists) from cache

NTURLCache - overrides NSURLCache

I seriously think this is an issue that is not working properly in iOS 8.1

The issue persists for iOS 11.x as well, though I have an iPad Mini running version iOS 9.3.5 which has perfectly working cache. Something is definetely broken with NSURLCache/URLCache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!