10

Despite using webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);, the WebView is still saving MB's worth of files into the cache. Is there a way to truly disable the cache?

Thanks

cottonBallPaws
  • 21,220
  • 37
  • 123
  • 171
  • I think this setting is for the second load of the page. I got this from the api for setCacheMode: The way the cache is used is based on the navigation option. For a normal page load, the cache is checked and content is re-validated as needed. When navigating back, content is not revalidated, instead the content is just pulled from the cache. This function allows the client to override this behavior. – Ashok Goli Aug 25 '11 at 09:08

2 Answers2

2

Nothing seems to be promising to disable cache completely.

It would be better to just ignore the cache and force webView to load new or fresh page each time.

if someone is worrying about occupied cache size, one can limit the cache size. There are plenty of methods to do so, have a look at my similar answer. Hope, the answer will give some hint about it.

But two things look promising to me for disabling the cache,

1) Make use of header parameters when you are loading a page,

Note : available for Android API 8+

    Map<String, String> noCacheHeaders = new HashMap<String, String>(2);
    noCacheHeaders.put("Pragma", "no-cache");
    noCacheHeaders.put("Cache-Control", "no-cache");
    view.loadUrl(url, noCacheHeaders);

2) If you have html page which you are going to load into the webView, you can add the following meta tags into the HTML page.

<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> 

Hope this will help you.

Community
  • 1
  • 1
Moin Ahmed
  • 2,898
  • 21
  • 33
-1

Try setAppCacheEnabled(false) in WebSettings.

Api reference: WebSettings.setAppCacheEnabled(boolean flag)

mdupls
  • 2,012
  • 1
  • 27
  • 40
J.G.Sebring
  • 5,934
  • 1
  • 31
  • 42
  • 4
    That is for the HTML5 Application Cache feature, and not for caching downloading content. – mparaz Jun 12 '12 at 06:43