当我使用NSURLConnection
从我的服务器获取数据时,iOS仍会缓存数据。在请求新数据时,iOS向我的服务器发送新请求,但文件仍然存储。
我使用NSURLRequestReloadIgnoringCacheData
并在connection:willCacheResponse:
中返回nil。
问题在于我使用自己的缓存对象,让iOS存储副本是一种愚蠢的行为。
我应该忽略这一点,还是应该以某种方式删除缓存?
更新
创建NSURLRequest
的代码:
request = [NSURLRequest requestWithURL:[NSURL URLWithString:URLString] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];
创建NSURLConnection
的代码:
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
NSURlConnectionDelegate
的代码:
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse {
return nil;
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[recivedData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
if (_handler) _handler(response, error, nil);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
if (_handler) _handler(response, nil, recivedData);
recivedData = nil;
response = nil;
}