I've found some similar posts, but they don't seem to have any effect with what I'm doing. I've got a UIWebView
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 UIWebView
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.
I load the document like so:
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've 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 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.
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.