I'm trying to get my app to use the Last-Modified
headers provided by my server.
Problem is that the app keeps caching responses from the server, and I have tried again and again to clear the caches, not allow it to cache responses, etc. but NOTHING is working. I have tried the below:
for AFNetworking
:
- (AFHTTPRequestOperationManager *)manager {
if (!_manager) {
_manager = [AFHTTPRequestOperationManager manager];
_manager.responseSerializer = [AFJSONResponseSerializer serializer];
[_manager.requestSerializer setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
}
return _manager;
}
Setting the NSURLRequestReloadIgnoringLocalCacheData
didn't work.
I tried this in my delegate
:
NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024
diskCapacity:20 * 1024 * 1024
diskPath:nil];
[NSURLCache setSharedURLCache:URLCache];
I even tried to set them to 0 to eliminate all possibility of caching. Still didn't work.
I also tried to delete cache as per below:
[[NSURLCache sharedURLCache] removeAllCachedResponses];
[[NSURLCache sharedURLCache] removeCachedResponsesSinceDate:last];
Even that didn't work. When I get a new response from the server, it simply reloads from cache yet again! Is there anything else I haven't tried that would help here? When I remove the Last-Modified
header for my servers response, everything works. But this is not the correct solution.
I have also read the below:
http://blog.originate.com/blog/2014/02/20/afimagecache-vs-nsurlcache/