SDURLCache icon indicating copy to clipboard operation
SDURLCache copied to clipboard

UIWebView caching failure for iOS>5.0

Open kremizask opened this issue 13 years ago • 5 comments

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 .

kremizask avatar May 15 '12 17:05 kremizask

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?

rs avatar May 15 '12 23:05 rs

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.

kremizask avatar May 15 '12 23:05 kremizask

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.

rs avatar May 16 '12 00:05 rs

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.

kremizask avatar May 16 '12 09:05 kremizask

You may try to add Last-Modified header.

rs avatar May 16 '12 10:05 rs