Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView NSURLRequestReloadIgnoringLocalCacheData doesn't actually ignore the cache

I have a UIWebView object, with the caching-policy specified as: NSURLRequestReloadIgnoringLocalCacheData

This should ignore whatever objects are in the local cache and retrieve the latest version of a site from the web.

However, after the first load of the site (ten resources in trace, HTTP GET), all subsequent loads of the site only retrieve a small subset of resources (three resources in trace, HTTP GET). The images all appear to be loaded from some local source.

I have confirmed that my sharedURLCache has a memory usage of 0 bytes, and a disk usage of 0 bytes. Whenever the process starts fresh, the full version of the site is retrieved again. This leads me to believe that these resources are being stored in an in-memory cache, but as I noted before, [[NSURLCache sharedURLCache] currentMemoryUsage] returns 0.

I have also tried explicitly removing the cached response for my request, but this seems to have no effect. What gives?

Edit: Furthermore, the NSHTTPCookieStorage is cleared before each load, and I can confirm that the subsequent loads retrieve four resources now instead of three. The caching issue persists regardless of the change.

like image 586
dodeskjeggen Avatar asked Feb 02 '26 04:02

dodeskjeggen


1 Answers

Have you tried appending a timestamp with the current time interval to the URL as a querystring parameter, e.g.

http://www.myhost.com/page.html?timestamp=123456789.0

I don't know if this works, it depends on how the cache is implemented, but it might be worth giving it a try; it's a bit hacky, but I've used this a long time ago in a galaxy far far away when doing Flash applets. I'm having the same problems now, and I've even tried using:

[[NSURLCache sharedURLCache] removeCachedResponseForRequest: request];

After the UIWebView has finished loading.

like image 88
pikuseru Avatar answered Feb 03 '26 20:02

pikuseru



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!