Webview is not clearing the cache

跟風遠走 提交于 2019-12-14 02:12:09

问题


To clear cache of WebView, I have used

   webview.getSettings().setAppCacheEnabled(false);
   webview.clearCache(true); 
   webview.loadUrl("about:blank");
   webview.reload()

             or 

   deleteDatabase("webview.db");
   deleteDatabase("webviewCache.db");

             or
   webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
   webview.clearCache(true);
   webview.clearHistory();

But nothing is clearing cache. Any suggestion??


回答1:


I have been trying to figure out the way to clear the cache, but all we could do from the above mentioned methods was remove the local files, but it never clean the RAM.

The API clearCache, frees up the RAM used by the webview and hence mandates that the webpage be loaded again.

public void clearCache (boolean includeDiskFiles)

includeDiskFiles boolean: if false, only the RAM cache is cleared

Clears the resource cache.

Note that the cache is per-application, so this will clear the cache for all WebViews used.

Suggested: To clear all the webview caches while you signOUT form your APP:

CookieSyncManager.createInstance(this);         
CookieManager cookieManager = CookieManager.getInstance();        
cookieManager.removeAllCookie();

For Lollipop and above:

CookieSyncManager.createInstance(this);         
CookieManager cookieManager = CookieManager.getInstance();        
cookieManager.removeAllCookies(ValueCallback);



回答2:


To clear all the webview caches while you signOUT form your APP:

CookieSyncManager.createInstance(this);         
CookieManager cookieManager = CookieManager.getInstance();        
cookieManager.removeAllCookie();

For Lollipop and above:

CookieSyncManager.createInstance(this);         
CookieManager cookieManager = CookieManager.getInstance();        
cookieManager.removeAllCookies(ValueCallback);

To clear the history, simply do:

this.WebView.clearHistory();


来源:https://stackoverflow.com/questions/51167882/webview-is-not-clearing-the-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!