我在将URLResponses缓存到磁盘时遇到问题。我想这是因为我要下载的数据需要重新加载时,它的http-header中的expires-tag会被满足,而不是更早。另外,我希望iPod touch用户能够在联机时下载一次数据,然后脱机使用。iphone:磁盘上的NSURLCache
我这样做是它重新推出应用程序时,缓存的事情工作正常的内存,但失败:从iOS的5
UPDATE
NSURLRequest* menuRequest = [NSURLRequest requestWithURL:mensaURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval: 10];
NSCachedURLResponse* cachedMenuResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:menuRequest];
if (cachedMenuResponse) {
// received data is a member of that class to which the asynchronous
// download writes and which is then being used in updateDataFromDownload
// to retrieve my data structure from the download.
self.receivedData = [NSMutableData dataWithData:[cachedMenuResponse data]];
[self updateDataFromDownload];
NSLog(@"using data from cache");
} else {
NSLog(@"opening connection");
[NSURLConnection connectionWithRequest:menuRequest delegate:self];
}
的文件说,这样做,或者至少暗示提供方法来设置缓存所使用的磁盘容量时。 – SmokeDispenser 2010-06-10 18:43:24
是的,我知道。我仍然认为它不被支持。例如,请参阅https://devforums.apple.com/message/182443#182443和http://github.com/rs/SDURLCache。 – 2010-06-10 19:36:09
谢谢你。 SDURLCache提供了一个简单的方法来完成我想要的:) – SmokeDispenser 2010-06-13 14:39:26