avatar

uniapp管理APP缓存

uniapp管理APP缓存

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// 获取
getCacheSize() {
// #ifdef APP-PLUS
plus.cache.calculate((size) => {
const sizeInt = parseInt(size)
if (sizeInt < 1024) {
this.cacheSize = '0KB'
} else if (sizeInt < 1048576) {
this.cacheSize = `${(sizeInt / 1024).toFixed(2)}KB`
} else {
this.cacheSize = `${(sizeInt / 1048576).toFixed(2)}MB`
}
})
// #endif
}

clearCache() {
// #ifdef APP-PLUS
uni.showModal({
title: '确认清除?',
content: '清除缓存将清空登录信息,需要重新启动应用进行登录',
success: (res) => {
if (res.confirm) {
plus.cache.clear(() => {
this.getCacheSize()
plus.runtime.restart()
})
}
},
})
// #endif
}
文章作者: pengweifu
文章链接: https://www.pengwf.com/2023/01/02/web/JS-Uniapp-ClearCache/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 麦子的博客
打赏
  • 微信
    微信
  • 支付宝
    支付宝

评论