HarmonyOS 浏览器 Web 组件如何获取缓存数据大小或缓存数据明细,如何删除本地缓存数据?

HarmonyOS
2024-12-17 14:20:07
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Excelsior_abit

可以通过removeCache()接口清除已经缓存的资源,参考demo:

struct WebComponent {
  @State mode: CacheMode = CacheMode.None;
  controller: web_webview.WebviewController = new web_webview.WebviewController();

  build() {
    Column() {
      Button('removeCache')
        .onClick(() => {
          try { // 设置为true时同时清除rom和ram中的缓存,设置为false时只清除ram中的缓存 this.controller.removeCache(true); } catch (error) {
            let e: business_error.BusinessError = error as business_error.BusinessError;
            console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
          }
        })
      Web({ src: 'www.huawei.com', controller: this.controller })
        .cacheMode(this.mode)
    }
  }
} 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.

可以参考缓存方案文档https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/web-cookie-and-data-storage-mgmt-V5

分享
微博
QQ
微信
回复
2024-12-17 16:46:30


相关问题
如何获取缓存数据和清理缓存
1243浏览 • 1回复 待解决
如何删除preferences中缓存数据
1155浏览 • 1回复 待解决
HarmonyOS uniapp数据缓存无效
688浏览 • 1回复 待解决
关于数据缓存问题咨询
1088浏览 • 1回复 待解决
数据缓存使用方面的推荐方案
1217浏览 • 1回复 待解决
HarmonyOS 如何清理 web 缓存
554浏览 • 1回复 待解决
HarmonyOS Web组件缓存问题
685浏览 • 1回复 待解决
HarmonyOS 如何清除Web缓存
614浏览 • 1回复 待解决
HarmonyOS 本地缓存问题?
1031浏览 • 0回复 待解决