rs / SDURLCache

URLCache subclass with on-disk cache support on iPhone/iPad
MIT License
798 stars 247 forks source link

UIWebView caching failure for iOS>5.0 #34

Open kremizask opened 12 years ago

kremizask commented 12 years ago

When the fallback to NSURLCache happens (iOS>5.0) caching for UIWebViews does not work. I assume it is because NSCachedURLResponse coming from an UIWebView has a storagePolicy set to NSURLCacheStorageAllowedInMemoryOnly as discussed here: https://github.com/rs/SDURLCache/pull/1 .

rs commented 12 years ago

I tested on iOS 5.1.1 on both device and simulator, and NSURLCacheStorageAllowed seems to be used for all UIWebView cache requests. How do you reproduce the issue?

kremizask commented 12 years ago

I am testing on iOS 5.1 on device/simulator. I have a simple View Controller with a UIWebView. I first run the app with an internet connection and the response is being cached. Then I run the app without an internet connection and the UIWebView does not load the html response. The webView delegate method webView:didFailLoadWithError: is being called with error'The Internet connection appears to be offline.'

I have set the cache-control:max-age header. However, when I do the same tests using the iOS 4.3 simulator, the UIWebView presents the html response both in online and offline mode.

rs commented 12 years ago

Just performed the very same test, worked well with iOS 5. I used this URL: http://rs.rhapsodyk.net/test/cache.html. Here is the test app: http://dl.dropbox.com/u/123346/SDURLCacheTest.zip.

kremizask commented 12 years ago

Interesting... I if I change your url with mine it doesn't work so it must have something to do with the response headers. Since I am not allowed to give you the actual url so that you can see for your self, could you please take a look at the response headers and tell me if you can think of anything? http://dl.dropbox.com/u/16899725/headers.png .

The funny thing is that as I mentioned before, it works with iOS 4.3, meaning it works with SDURLCache.

rs commented 12 years ago

You may try to add Last-Modified header.