HarmonyOSBaseLibs/src/main/ets/utils/AppStorageHelper.ets
2024-10-14 19:05:41 +08:00

35 行
672 B
Plaintext

/**
* 永久化存储,存储在本地文件
*/
export class AppStorageHelper {
/**
* 缓存
* @param key
* @param value
*/
public static save<T>(key: string, value: T | undefined) {
if (value === undefined || value === null) {
PersistentStorage.deleteProp(key)
} else {
PersistentStorage.persistProp(key, value)
}
}
/**
* 删除缓存
* @param key
* @param value
*/
public static delete(key: string) {
PersistentStorage.deleteProp(key)
}
/**
* 获取已缓存的内容
* @param key
* @returns
*/
public static get<T>(key: string): T | undefined {
return AppStorage.get<T>(key)
}
}