views:

592

answers:

3

When using NSURLRequest on the iPhone, what are the real world performance differences between the various NSURLRequestCachePolicy settings? I am specifically interested in the cache policy's effect on the the user's perception of the speed at which UIWebView pages display.

I have been using the default NSURLRequestCachePolicy but I think that perhaps NSURLRequestReloadRevalidatingCacheData could be best for most cases especially when going back to a previous page.

If you've used various cache policies under real-world conditions, which policy proved optimum in a particular circumstance? What policy provides the best overall performance over the three different types of iPhone connections, wi-fi, 3G and Edge? Does the cache policy even have any significant effect on the user's perception of page loading speed or should I be looking elsewhere to optimize UIWebView's display time?

Update:

There seems to be a consensus that UIWebView appears to ignore the cache settings on any NSURLRequest given it. I do not have complete confidence that this is the final answer but barring the time to do some extensive testing, I cannot gainsay it. Therefore, I am accepting the highest rated answer. However, I would advise that you take the answers with a grain of salt if the matter is of importance to your project. -- TechZen.

+1  A: 

I don't think this will make any difference on your UIWebView loading times. UIWebView is built on WebKit, and they're not using NSURLConnection internally (they are at a much lower level and use CFNetwork directly).

This is probably not what you want to hear, but probably the best way to speed up UIWebView loading time is to not use a UIWebView. Rendering web pages is pretty CPU-intensive. In fact, MobileSafari is actually mostly CPU-bound, not network-bound -- notice how long it takes it to fill in that checkerboard pattern when scrolling, for example. For really fast, quickly loading content, it's best to create a native interface in Cocoa.

Colin Barrett
Are you certain about this? The `-[UIWebView loadRequest]` does accept a `NSURLRequest` which does have a cache policy attached. Is that just ignored? Why use a request if it is not used to managed the connection? I do not have the time to create a webview from scratch so I need to optimize this one.
TechZen
You're asking for implementation details about Apple frameworks that I don't know about. The easiest way to figure out if it affects perceived performance is to do your own testing.
Colin Barrett
Looks like I will have to but such testing is difficult because you can only sample a small number of pages. It's hard to get good data. I had hoped someone knew the details but I suppose it's an esoteric question.
TechZen
A: 

I just did a grep on the WebKit sources, and didn't find any use of the -[NSURLRequest cachePolicy].

Graham Lee
A: 

I a few hours for a project trying to get a UIWebView to cache pages I was loading. It proved impossible from the application side without storing the files locally. It seems that UIWebView ignores the NSURLRequestCachePolicy completely.

Yahoo! has some info on the iPhone's caching behaviour.

Colin Gislason
The Yahoo! page is interesting but it is two years old. I'm not sure how relevant it is.
TechZen
Good point. At very least, newer hardware probably caches more.
Colin Gislason