When loading documents containing images (for example, a Microsoft Word docx file), UIWebView will always cache images when it receives a memory warning, regardless of cache policy.
The following is an example code snippet:
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:1024 * 1024 diskCapacity:0 diskPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"URLCache"]]; [NSURLCache setSharedURLCache:sharedCache]; NSURLRequest* req = [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.its.swinburne.edu.au/about/projects/templates/TechnicalSpecificationTemplatev1.1-[ProjectName]-[ver]-[YYYYMMDD].docx"] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
In these circumstances, when a memory warning occurs, a new folder is created in the tmp directory of the application, usually called DiskImageCache-random_suffix , and all the images in the open document are saved here.
After UIWebView loads a new request, if I call
[sharedCache removeAllCachedResponses]
these temporary images are deleted.
The only way to prevent image caching is to call
[NSClassFromString(@"WebCache") performSelector:@selector(setDisabled:) withObject:[NSNumber numberWithBool:YES]];
but that means using a private API.
Is there a βfriendly Appleβ way to achieve this?
source share