# harmony-utils之CacheUtil,緩存工具類
## harmony-utils 簡介與說明
------
[harmony-utils](https://ohpm.openharmony.cn/#/cn/detail/@pura%2Fharmony-utils) 一款功能豐富且極易上手的HarmonyOS工具庫,借助眾多實用工具類,致力于助力開發者迅速構建鴻蒙應用。其封裝的工具涵蓋了APP、設備、屏幕、授權、通知、線程間通信、彈框、吐司、生物認證、用戶首選項、拍照、相冊、掃碼、文件、日志,異常捕獲、字符、字符串、數字、集合、日期、隨機、base64、加密、解密、JSON等一系列的功能和操作,能夠滿足各種不同的開發需求。
[picker_utils](https://ohpm.openharmony.cn/#/cn/detail/@pura%2Fpicker_utils) 是harmony-utils拆分出來的一個子庫,包含PickerUtil、PhotoHelper、ScanUtil。
下載安裝
`ohpm i @pura/harmony-utils`
`ohpm i @pura/picker_utils`
//全局初始化方法,在UIAbility的onCreate方法中初始化 AppUtil.init()
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
AppUtil.init(this.context);
}
## API方法與使用
------
##### has 緩存中的數據是否存在
let pwd = CacheUtil.has("pwd");
ToastUtil.showToast(緩存是否存在:${pwd}
);
##### put 將數據存入緩存中
CacheUtil.put("pwd", "ABCD@12345");
ToastUtil.showToast("緩存密碼成功");
##### get 獲取緩存中的數據
let pwd = CacheUtil.get("pwd");
ToastUtil.showToast(取值:${pwd}
);
##### remove 刪除key對應的緩存
CacheUtil.remove("pwd");
ToastUtil.showToast(緩存移除成功!
);
##### isEmpty 判斷緩存是否為空
let blEmpty = CacheUtil.isEmpty();
ToastUtil.showToast(緩存是否為空:${blEmpty}
);
##### clear 清除緩存數據
CacheUtil.clear();
ToastUtil.showToast(清除緩存數據成功
);
## 創作不易,請給童長老點贊
審核編輯 黃宇
-
Harmony
+關注
關注
0文章
104瀏覽量
2984
發布評論請先 登錄
評論