Lcstest Test
Lcstest Test

Reputation: 113

How clear UIWebView cache

How to clear the cache of a UIWebView?

I am making a simple application (with only three buttons (back, forward, refresh) and a UIWebView) and I realized that in my Documents & Data iPhone gets a very high value of Cache. I already looked at various documents and posts (even here at StackOverflow) but none solved the problem. If you need lines of codes, ask.

Upvotes: 2

Views: 4763

Answers (2)

Kiran
Kiran

Reputation: 345

[[NSURLCache sharedURLCache] removeCachedResponseForRequest:NSURLRequest];

This would remove a cached response for a specific request. There is also a call that will remove all cached responses for all requests ran on the UIWebView:

[[NSURLCache sharedURLCache] removeAllCachedResponses];

After that, you can try deleting any associated cookies with the UIWebView:

for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {

    if([[cookie domain] isEqualToString:someNSStringUrlDomain]) {

        [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
    }
}

Upvotes: 6

Ravindra Bagale
Ravindra Bagale

Reputation: 17655

its so simple

[[NSURLCache sharedURLCache] removeAllCachedResponses];

Upvotes: 0

Related Questions