HarmonyOS开发中,关于清理缓存的问题?

有没有清理缓存的一套逻辑和相关代码呢?

阅读 683
1 个回答

目前没有直接清除缓存的 api,清除缓存可以使用文管侧 api,fs.rmdirSync 遍历请删除缓存文件夹。cacheSize 包含以下几个目录:
/data/storage/el1/base/cache
/data/storage/el1/base/haps/entry/cache
/data/storage/el2/base/cache
/data/storage/el2/base/haps/entry/cache
相关代码示例:

let context = getContext(this) as common.UIAbilityContext;   
fs.rmdirSync(context.cacheDir);

参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-refere...https://developer.huawei.com/consumer/cn/doc/harmonyos-refere...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进