I found a few similar posts, but they don't seem to affect what I'm doing. I have a UIWebView that I use to display local content in my package. In particular, I am showing a docx file. The user rarely has to ever look at this document, and my application is closely related to memory, so I want UIWebView not to cache the document. Another viable option is to clear the cache when the user leaves the view. I completely agree with the need to download it from scratch every time a user enters a view.
I load the document like this:
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];
In my attempts to stop the caching I tried:
[[NSURLCache sharedURLCache] setMemoryCapacity:0]; [[NSURLCache sharedURLCache] setDiskCapacity:0];
and
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil]; [NSURLCache setSharedURLCache:sharedCache]; [sharedCache release]; sharedCache = nil;
AND:
if(request) { [[NSURLCache sharedURLCache] removeCachedResponseForRequest:request]; } [[NSURLCache sharedURLCache] removeAllCachedResponses];
I also tried setting a policy for caching web views, but it seems to be just memory, since when I released the web view, there was still memory. When re-entering and reusing, he did not use the same memory.
I do not think this is the right direction. All of them have been flagged as ways to stop web pages from caching, but they do not seem to affect local files. I really don't know where else to go with this. If someone knows how to make the cache clear or prevent caching, I would really appreciate help.
ios uiwebview nsurlcache
user675446
source share