M
M
max_sokolov2014-02-11 13:22:46
iOS
max_sokolov, 2014-02-11 13:22:46

Why can't UIWebView be trained to access the local cache while reloading the same web page?

Good afternoon guys!
Faced a problem - it is not possible to disaccustom UIWebView to access the local cache during reloading of the same web page. I need each new request to go to the Internet (relevant only for iOS 7).
Here's what's available:
1) A custom NSURLProtocol that just keeps track of http requests.
2) There is a UIWebView in the first UIViewController . In this UIWebView we load the website:

NSMutableURLRequest *request =[NSMutableURLRequest requestWithURL:
[NSURL URLWithString:@"http://site.ru"] 
cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
3) While loading the page in NSURLProtocol, we conditionally see 20 requests to this site.ru (images, css, js, etc. are loaded)
4) In the second UIViewController with our UIWebView , we make a similar request with the same website.
5) In NSURLProtocol, we conditionally see only 5 requests to the same site.ru (images, css, js are not loaded)
Obviously, UIWebView got into the cache and got everything it needed from there, which I need to avoid.
What I tried:
1) Initialize the cache on my own (also pass zeros as memoryCapacity and diskCapacity).
NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:
4 * 1024 * 1024 diskCapacity:32 * 1024 * 1024 diskPath:@"dir"];
[NSURLCache setSharedURLCache:URLCache];
2) Before sending the request, call:
[[NSURLCache sharedURLCache] removeCachedResponseForRequest:(NSURLRequest *)];
[[NSURLCache sharedURLCache] removeAllCachedResponses];
3) Clear the cache directory NSCachesDirectory (horror!)
4) Manipulate cachePolicy flags NSURLRequestReloadIgnoringCacheData 5 ) Avoid caching at the NSURLProtocol level :

- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:
(NSCachedURLResponse *)cachedResponse {
 return nil; }
6) Add the time parameter site.ru?timestamp=21324353 to the address (horror!)
7) Inherit NSURLCache and avoid caching:
- (NSCachedURLResponse*)cachedResponseForRequest:(NSURLRequest*)request {
    return nil; }

None of the above methods affect the UIWebView in any way . One gets the impression that he has some kind of his own cache, which cannot be reached.
Has anyone come across? Maybe I missed something.

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
S
sojik, 2014-02-13
@sojik

And try to do in paragraph 2 also like this
[[NSURLCache sharedURLCache] removeAllCachedResponses];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
they say sometimes it helps)
PS colleague, well, you put tags) no one will find you like that)

A
Alexander Vasyuchenko, 2014-02-27
@alexv1981

It's strange, of course. because the request contains the NSURLRequestReloadIgnoringCacheData flag. Those. should not store anything in the cache. If this is only on ios7, then this is some kind of flaw with apple. How does the same code behave on ios6?

S
Shiny2, 2015-05-11
@Shiny2

I'm suffering with the same problem. where this cache lives is not clear. but obviously somewhere inside the device

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question