AiOsN
AiOsN

Reputation: 2345

AFNetworking 2.0 Cache Issue

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).....

Upvotes: 2

Views: 121

Answers (1)

NSIRLConnection
NSIRLConnection

Reputation: 104

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.

Upvotes: 1

Related Questions