当前位置:网站首页>5+API,清除应用缓存

5+API,清除应用缓存

2022-06-26 12:32:00 sunly_

// 清除缓存
clear(){
    
	plus.cache.clear(()=> {
    
		uni.showToast({
    
			title: '清理成功,请重新启动APP',
		});
		setTimeout(()=>{
    
			plus.runtime.quit();
		},1500)
		this.getSize();
	});
},
// 计算缓存大小
getSize() {
    
	plus.cache.calculate((size) => {
    
		if (size == 0) {
    
			this.cacheSize = "0B";
		} else if (size < 1024) {
    
			this.cacheSize = size + "B";
		} else if (size < 1048576) {
    
			this.cacheSize = (size / 1024).toFixed(2) + "KB";
		} else if (size < 1073741824) {
    
			this.cacheSize = (size / 1048576).toFixed(2) + "MB";
		} else {
    
			this.cacheSize = (size / 1073741824).toFixed(2) + "GB";
		}
		console.log(this.cacheSize);
	})
},

Cache模块用于管理应用缓存,通过plus.cache获取缓存管理对象。

原网站

版权声明
本文为[sunly_]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_40745143/article/details/125459573