artifacts / AFCache

AFCache is an HTTP cache for iOS and OSX seeking towards full RFC2616 compliance
Apache License 2.0
361 stars 43 forks source link

storeCachedResponse: not called #9

Closed dqueffeulouatw closed 9 years ago

dqueffeulouatw commented 13 years ago

Actually this is not an AFCache issue, more a discussion about a problem with NSURLCache at least with UIWebView.

It seems like NSURLCache always calls cachedResponseForRequest: but not always storeCachedResponse:forRequest:.

I have a page with some images from the same directory and with the same cache headers, and some are cached but not all because storeCachedResponse:forRequest: is not called.

Sometimes if I navigate thru the pages and come back to the first, it is called.

So it may be difficult to cache a page with a single shot. We can't be sure all the resources is in the cache.

aherlambang commented 12 years ago

I am also seeing this issue with UIWebView not calling storeCachedResponse all the time but is calling cachedResponseForRequest

artifacts commented 9 years ago

see http://stackoverflow.com/questions/7166422/nsurlconnection-on-ios-doesnt-try-to-cache-objects-larger-than-50kb

Don't usw AFURLCache, instead register AFHTTPURLProtocol for http requests:

[NSURLProtocol registerClass:[AFHTTPURLProtocol class]];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"]];
[self.webView loadRequest:request];