的WebView的LOAD_NO_CACHE设置还是将文件保存到磁盘? [英] WebView's LOAD_NO_CACHE setting still saves files to the disk?

查看:1619
本文介绍了的WebView的LOAD_NO_CACHE设置还是将文件保存到磁盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管使用 webview.getSettings()setCacheMode(WebSettings.LOAD_NO_CACHE); ,web视图仍然保存文件到高速缓存中的MB的价值。有没有办法真正禁用缓存?

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?

感谢

推荐答案

一切似乎是有前途完全禁用缓存。

Nothing seems to be promising to disable cache completely.

这将是更好地忽略缓存和部队web视图为新的或新的一页,每次加载。

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)利用头参数,当您正在加载一个网页,

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

注:可用于Android API 8 +

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)如果你有html页面,你会加载到web视图, 你可以添加以下meta标签到HTML页面。

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.

这篇关于的WebView的LOAD_NO_CACHE设置还是将文件保存到磁盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆