You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android中WebSettings.LOAD_NO_CACHE是全局生效还是仅针对单个WebView?

WebView中LOAD_NO_CACHE的作用范围说明

WebSettings.LOAD_NO_CACHE 仅针对当前WebView对象生效,不会影响应用内其他WebView实例。

核心区别与原理

  • clearCache(true) 是应用级的全局缓存清理操作,根据官方文档说明:

    Clears the resource cache. Note that the cache is per-application, so this will clear the cache for all WebViews used.
    执行后会清空所有WebView的内存和磁盘缓存,属于一次性全局生效的动作。

  • WebSettings.LOAD_NO_CACHE 是单个WebView实例的缓存加载策略配置:
    WebSettings是每个WebView独有的配置对象,通过webView.settings获取的配置仅作用于当前WebView。设置该模式后,当前WebView后续加载页面时会跳过缓存直接从网络获取资源,其他WebView的缓存策略不受影响。

正确使用示例

// 为当前WebView设置不使用缓存的加载策略
webView?.settings?.cacheMode = WebSettings.LOAD_NO_CACHE

内容的提问来源于stack exchange,提问作者choi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 11:42:02