Does AFNetworking
cache still work for objective-C? I have been trying to cache API response using AFNetworking
, but it seems not to work anymore.
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSString *requestURL = [NSString stringWithFormat:@"http://ssssssssss.com"];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[manager.requestSerializer setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[manager GET:requestURL parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject).....
NSURLRequestReloadIgnoringLocalCacheData is a cache policy that forces the data to be loaded from the original source, so locally cached data will not be used.
Use:
NSURLRequestUseProtocolCachePolicy for default behavior
NSURLRequestReturnCacheDataElseLoad for loading from cache, and loading from the original source if it does not exist in the cache.
NSURLRequestReturnCacheDataDontLoad for loading from cache, and not loading from the original source if it does not exist in the cache.