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
相关产品推荐
相关产品推荐

