Note that there are some explanatory texts on larger screens.

plurals
  1. POclearing a webviews cache for local files
    text
    copied!<p>I've found some similar posts, but they don't seem to have any effect with what I'm doing. I've got a <code>UIWebView</code> that I'm using to display local content in my bundle. Specifically I'm displaying a docx file. The user should rarely ever look at this document, and my app is tight on memory, so what I want to do is prevent the <code>UIWebView</code> from caching the document. Another viable option is to clear the cache when the user leaves the view. I'm totally ok with having to load it from scratch every time the user enters the view. </p> <p>I load the document like so: </p> <pre><code>NSString * path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Intro text"] ofType:@"docx"]; NSURL * url = [NSURL fileURLWithPath:path]; request = [NSURLRequest requestWithURL:url]; doc_view_rect = CGRectMake(5,105,self.view.frame.size.width,self.view.frame.size.height); doc_viewer = [[UIWebView alloc] initWithFrame:doc_view_rect]; [doc_viewer loadRequest:request]; </code></pre> <p>In my attempts to stop the caching I've tried: </p> <pre><code>[[NSURLCache sharedURLCache] setMemoryCapacity:0]; [[NSURLCache sharedURLCache] setDiskCapacity:0]; </code></pre> <p>And:</p> <pre><code>NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil]; [NSURLCache setSharedURLCache:sharedCache]; [sharedCache release]; sharedCache = nil; </code></pre> <p>And: </p> <pre><code>if(request) { [[NSURLCache sharedURLCache] removeCachedResponseForRequest:request]; } [[NSURLCache sharedURLCache] removeAllCachedResponses]; </code></pre> <p>I also tried setting the web-views caching policy, but that just seemed to eat memory, as when I released the webview, there was still memory left behind. When I re-entered and realloced it didn't use the same memory.</p> <p>I don't think this is the right direction though. These were all tagged as ways to stop webpages from caching, but they seem to have no effect with local files. I'm really not sure where else to go with this one. If anyone knows how to force the cache to clear, or prevent caching in the first place I would greatly appreciate some help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload