HarmonyOSBaseLibs/src/main/ets/utils/AppStorageHelper.ets

35 行
641 B
Plaintext

2024-05-07 17:41:21 +08:00
/**
* 永久化存储,存储在本地文件
*/
export class AppStorageHelper {
/**
2024-09-24 17:52:59 +08:00
* 缓存
2024-05-07 17:41:21 +08:00
* @param key
* @param value
*/
2024-09-24 17:52:59 +08:00
public static save<T>(key: string, value: T | undefined) {
if (!value) {
PersistentStorage.deleteProp(key)
} else {
PersistentStorage.persistProp(key, value)
}
2024-05-07 17:41:21 +08:00
}
/**
2024-09-24 17:52:59 +08:00
* 删除缓存
* @param key
* @param value
*/
public static delete(key: string) {
PersistentStorage.deleteProp(key)
}
/**
* 获取已缓存的内容
2024-05-07 17:41:21 +08:00
* @param key
* @returns
*/
2024-09-24 17:52:59 +08:00
public static get<T>(key: string): T | undefined {
2024-09-24 17:50:53 +08:00
return AppStorage.get<T>(key)
2024-05-07 17:41:21 +08:00
}
}