android - 如何让 webview 在 html 内容发生变化时自动刷新其缓存?

标签 android caching webview

在我的安卓应用中我设置了

webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);

为 webview 启用缓存。问题是,当网页内容改变时(我不知道),它仍然使用旧的缓存内容。 如何在不使用缓存的情况下,当在线网页内容发生变化时自动重新缓存内容?

如有任何建议,我们将不胜感激。

最佳答案

我相信您无法确定网页内容是否已更改。

但是,当您启用对 webview 的缓存时,它会自动为 webview 缓存提供一个过期时间,这意味着,如果 webView 缓存过期,它将再次加载网页。如果您使用 WebSetting.LOAD_DEFAULT

,这是可能的

如果您觉得 html 页面的内容可能会更频繁地更改,那么您不应该使用 WebSetting.LOAD_CACHE_ELSE_NETWORK,因为根据文档:

public static final int LOAD_CACHE_ELSE_NETWORK

Use cached resources when they are available, even if they have expired. Otherwise load resources from the network. 

这将加载 html 页面的缓存版本,即使它已过期。

关于android - 如何让 webview 在 html 内容发生变化时自动刷新其缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30860886/

相关文章:

android - android 中的 facebook 应用程序中的哈希键无效

android - 旧 Android 设备上的 OpenSL slCreateEngine 错误

android - 如何将原始文件夹中的自定义声音添加到 RingtonePreference 中以显示?

android.database.cursor 索引越界异常?

iphone - 如何从 webview 调用 iphone native 应用程序

java - 我应该如何在 Spring 中实现缓存对象/系统?

caching - CacheOutput 属性忽略 Azure 托管的 Redis 缓存

firefox - 如何从 :cache? device=disk 获取内容

ios - Swift - 如何在全屏视频中启用横向?

android - android webview 浏览器是否支持 html5 功能?