2013-12-10 57 views
0

我想了很多与ASIHTTPRequestcache响应数据,我已经阅读文档,并尝试了很多解决方案,但没有运气:(ASIHTTPRequest缓存响应数据

这是我的代码:

_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"); 

} 
+1

停止使用ASIHTTPRequest并开始使用AFNetworking。几年来ASI不受支持(我认为他们甚至没有ARC支持)。 – Eimantas

+0

@Eimantas我打算转移到AFNetworking,但目前没有..我正在使用ASIHTTPRequest处理现有项目,所以在转移到AFNetworking之前我需要一些时间。 – Atrash

回答

0

您使用ASIFormDataRequest,它基本上是一个POST操作。

由于POST不是幂等操作,我怀疑这是缓存。

也许你应该开始用GET请求测试你的缓存机制。

一些参考:Is it possible to cache POST methods in HTTP?