3

I'm having this problem with UIWebView:

Customer asked to check the cache policy of our UIWebView because, according to him, content updated on the server didn't appear on the device when reloading a page.

Now, I saw that the NSURLRequest that we're passing to the UIWebView has a cachePolicy of NSURLRequestReturnCacheDataElseLoad, which could enforce the customer thesis. If I understand this correctly, only the first request is loaded from the server, subsequent requests are loaded from the cache.

Then I changed the cachePolicy to NSURLRequestUseProtocolCachePolicy, since I saw in the NSURLRequest.h headers that the interesting NSURLRequestReloadRevalidatingCacheData is "unimplemented".

Everything seemed work well, until I did a rollback to the previous policy and I saw on Charles that everytime the UIWebView disappeared and then reappeared on the screen, a new request was done on the server, and mocking simple changes to the resulting page I could also see changes on the device.

Header returned by the server are btw:

Date    Tue, 13 Aug 2013 09:46:46 GMT
Content-Encoding    gzip
Server  Apache
ETag    "791e833a504a3a0f11fc74605ea244d2"
Vary    Accept-Encoding
Content-Type    text/html; charset=utf-8
Cache-Control   public, max-age=60
Accept-Ranges   bytes
Content-Length  2685
Expires Tue, 13 Aug 2013 09:47:46 GMT

For a request done on the 13th of August at 11:46 GMT+2 (Berlin)

So to me the headers look fine, but still the UIWebView tries everytime to reload the contents.

I also took a look in the webView:shouldStartLoadWithRequest:navigationType: delegate method and I saw that the cachePolicy of the request was always set to 1 (NSURLRequestReloadIgnoringLocalCacheData).

How is this possible? And also how is then possible that the customer complained about the problem (he even sent me a screenshot, so this is not invented)

Thank you for your help

Vik
  • 1,877
  • 12
  • 18

1 Answers1

0

Eventually I manually made the NSURLRequest using a NSURLRequestUseProtocolCachePolicy and started a NSURLConnection with that. Then, I loaded the HTML string when the connection finished loading.

Vik
  • 1,877
  • 12
  • 18