我正在尝试使用ASIHTTPRequest
到cache
响应数据,我已阅读文档并尝试了许多解决方案,但没有运气:(
这是我的代码:
_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");
}
答案 0 :(得分:0)
您正在使用ASIFormDataRequest,它基本上是一个POST操作。
由于POST不是幂等操作,我怀疑它是可缓存的。
也许您应该开始使用GET请求测试缓存机制。