0

I'm trying a lot with ASIHTTPRequest to cache the response data, I have read the documentation and tried many solutions, but no luck :(

This is my code:

_request = [[ASIFormDataRequest alloc]initWithURL:[NSURL URLWithString:NSLocalizedString(@"kBaseUrl", nil)]];
_request.delegate = self;
[_request setDownloadCache:[ASIDownloadCache sharedCache]];
[[ASIDownloadCache sharedCache] setShouldRespectCacheControlHeaders:NO];
[_request setCachePolicy:ASIAskServerIfModifiedCachePolicy|ASIFallbackToCacheIfLoadFailsCachePolicy];//ASIAskServerIfModifiedCachePolicy|ASIFallbackToCacheIfLoadFailsCachePolicy
[_request setSecondsToCache:60*60*24*2]; // Cache for 2 days
[_request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
[_request setDefaultResponseEncoding:NSUTF8StringEncoding];
[_request setDidFinishSelector:@selector(doneLoadingBody:)];
[_request setDidFailSelector:@selector(failedLoadingBody:)];
[_request setRequestMethod:@"POST"];
[_request setShouldContinueWhenAppEntersBackground:YES];
[_request setPostValue:@"someValue" forKey:@"name"];
[_request setPostValue:@"someValue" forKey:@"key"];
[_request setPostValue:@"someValue" forKey:@"key"];
[_request startAsynchronous];

if ([_request didUseCachedResponse] == NO) {

    NSLog(@"Did not Cache Body");

}
Eimantas
  • 48,927
  • 17
  • 132
  • 168
M.Alatrash
  • 1,270
  • 1
  • 12
  • 30
  • 1
    Stop using ASIHTTPRequest and start using AFNetworking. ASI is unsupported for quite few years now (I don't think they even have ARC support). – Eimantas Dec 10 '13 at 08:50
  • @Eimantas i'm planning to move to AFNetworking but not at the current time.. i'm working on an existing project with the ASIHTTPRequest, so I need some time before moving to AFNetworking. – M.Alatrash Dec 10 '13 at 08:53

1 Answers1

0

You're using ASIFormDataRequest and it's basically a POST operation.

Since POST is not an idempotent operation, i doubt it is cacheable.

Maybe you should start testing your cache mechanism with a GET request.

Some reference: Is it possible to cache POST methods in HTTP?

Community
  • 1
  • 1
Egist Li
  • 624
  • 5
  • 9