我想设置一个60秒到期的缓存。 xml文件已成功缓存,但即使服务器更新数据,缓存仍会在时间到期后保持使用。因此,我想弄清楚我做了哪些错误,并寻求任何解决方案来解决它。
我发送的用于发送异步http请求的代码:
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]];
[[ASIDownloadCache sharedCache] setShouldRespectCacheControlHeaders:NO];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestFinished:)];
[request setDidFailSelector:@selector(requestFailed:)];
[request setSecondsToCache:60];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
[request setCachePolicy:ASIOnlyLoadIfNotCachedCachePolicy | ASIAskServerIfModifiedWhenStaleCachePolicy];
[request setNumberOfTimesToRetryOnTimeout:2];
[request setTimeOutSeconds:30];
[[self queue] addOperation:request];
我写的用于接收请求的代码:
- (void)requestFinished:(ASIHTTPRequest *)request {
BOOL success = [request didUseCachedResponse];
NSLog(@"Success is %@\n", (success ? @"YES" : @"NO"));
NSData *data = [request responseData];
}
这是xml的标题:
Request Method:GET
Status Code:200 OK
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Type:application/xml;charset=utf-8
Date:Mon, 15 Apr 2013 08:49:59 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8b mod_jk/1.2.26 PHP/5.2.5
Set-Cookie:Expires=Mon, 15-Apr-2013 08:50:29 GMT;
这是我在/ iPhone模拟器/ 5.0 / Applications / XXX / Library / Caches / ASIHTTPRequestCache / PermanentStore中找到的.cachedheaders文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Connection</key>
<string>Keep-Alive</string>
<key>Content-Length</key>
<string>9296</string>
<key>Content-Type</key>
<string>application/xml;charset=utf-8</string>
<key>Date</key>
<string>Fri, 12 Apr 2013 09:49:33 GMT</string>
<key>Keep-Alive</key>
<string>timeout=5, max=99</string>
<key>Server</key>
<string>Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8b mod_jk/1.2.26 PHP/5.2.5</string>
<key>Set-Cookie</key>
<string>Expires=Fri, 12-Apr-2013 09:50:04 GMT;</string>
<key>X-ASIHTTPRequest-Expires</key>
<real>1365989738.766006</real>
<key>X-ASIHTTPRequest-Response-Status-Code</key>
<integer>200</integer>
</dict>
</plist>
提前感谢您的帮助!
答案 0 :(得分:0)
我已经通过阅读这篇文章解决了这个问题。
https://groups.google.com/forum/#!topic/asihttprequest/Z0XRuBlZBSY
我们必须修改ASIDownloadCache中的代码。
我认为这是ASIHTTPRequest的错误。