Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you clear a UIWebView's cache?

Essentially, I need to know how to make a UIWebView erase everything when you terminate the app. Basically, that includes all cookies and information held by the webView through usage.

Is there any way to simply clear it so that it's like new each time?

like image 344
JTApps Avatar asked Jan 03 '12 18:01

JTApps


People also ask

How do I check my Webview cache?

webview cache is saved into /data/data/[your_package_name]/cache/org.

What is Webview cache?

CacheWebView is a custom implement of Android WebView resource interceptor. It beyond system WebView cache space limit, let cache config more simple ,fast and flexible. Visit website by offline.

Can I clear cache in Android system Webview?

Click on the Storage option on the app information window. It will open a new window with the clear cache and data option. Lastly, try to update the android webview app from Google PlayStore.


1 Answers

UIWebView doesn't cache, it's the NSURLConnection it uses. Any of the following used to work, and follows the documentation of NSURLCache:

// remove all cached responses
[[NSURLCache sharedURLCache] removeAllCachedResponses];

// set an empty cache
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];

// remove the cache for a particular request
[[NSURLCache sharedURLCache] removeCachedResponseForRequest:request];

But I'm not sure if it does now (iOS 5). Other options are using a custom cache: SDURLCache or overriding connection:withCacheResponse:. If you find out what is the current behavior please comment.

like image 198
Jano Avatar answered Sep 30 '22 01:09

Jano