質問

Here is the really simple call I make :

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];

I try with 2 random pdf urls found on google (searching "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";

They both have similar headers (using allHeaderFields in connection:didReceiveResponse:) :

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

But connection:willCacheResponse: is only called for url B. And I find only url B in the Cache.db sqlite database.

Why isn't url A cached?

役に立ちましたか?

解決

Ok, so the problem comes from the size of the file.

It seems that NSURLCache won't cache files that are bigger than 5% of the disk capacity it has.

My NSURLCache was set with 50MB of disk capacity, so files bigger than 2.5MB aren't cached.

Extending the disk capacity solved my problem.

ps : you can extend the disk capacity to 2GB max, so files in cache can't be bigger than 100MB.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top