下面是我做的一个非常简单的调用:
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:500];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
[connection start];我试着在google上找到两个随机的pdf urls (搜索"truc filetype:pdf"):
A) NSString *urlString = @"http://www.eatletruc.com/letruc.menu0411.pdf";
B) NSString *urlString = @"http://www.botruc.com/boat-specs/C-Truc-7.pdf";它们都有类似的头部(在connection:didReceiveResponse:中使用allHeaderFields ):
a)
"Accept-Ranges" = bytes;
Connection = "Keep-Alive";
"Content-Length" = 2641705;
"Content-Type" = "application/pdf";
Date = "Thu, 11 Apr 2013 08:53:39 GMT";
Etag = "\"19a7b55-284f29-4a0a5e94ae1a7\"";
"Keep-Alive" = "timeout=5, max=100";
"Last-Modified" = "Mon, 11 Apr 2011 15:05:50 GMT";
Server = Apache;b)
"Accept-Ranges" = bytes;
Connection = "Keep-Alive";
"Content-Length" = 343793;
"Content-Type" = "application/pdf";
Date = "Thu, 11 Apr 2013 08:55:38 GMT";
Etag = "\"b6864a-53ef1-49400c1d95800\"";
"Keep-Alive" = "timeout=5, max=100";
"Last-Modified" = "Mon, 01 Nov 2010 17:01:20 GMT";
Server = "Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635";但是connection:willCacheResponse:只为url调用,并且我在Cache.db sqlite数据库中只找到url。
为什么url A没有缓存?
发布于 2013-04-15 20:05:37
好的,所以问题来自于文件的大小。
看起来NSURLCache不会缓存超过其磁盘容量5%的文件。
我的NSURLCache设置了50MB的磁盘容量,所以大于2.5MB的文件不会被缓存。
扩展磁盘容量解决了我的问题。
ps :您可以将磁盘容量扩展到最大2 2GB,因此缓存中的文件不能超过100MB。
https://stackoverflow.com/questions/15945613
复制相似问题