AppStorageHelper.ets 672 B

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * 永久化存储,存储在本地文件
  3. */
  4. export class AppStorageHelper {
  5. /**
  6. * 缓存
  7. * @param key
  8. * @param value
  9. */
  10. public static save<T>(key: string, value: T | undefined) {
  11. if (value === undefined || value === null) {
  12. PersistentStorage.deleteProp(key)
  13. } else {
  14. PersistentStorage.persistProp(key, value)
  15. }
  16. }
  17. /**
  18. * 删除缓存
  19. * @param key
  20. * @param value
  21. */
  22. public static delete(key: string) {
  23. PersistentStorage.deleteProp(key)
  24. }
  25. /**
  26. * 获取已缓存的内容
  27. * @param key
  28. * @returns
  29. */
  30. public static get<T>(key: string): T | undefined {
  31. return AppStorage.get<T>(key)
  32. }
  33. }