CacheDataSaveUtil.ets 637 Bytes
import { KVStoreHelper, StringUtils } from 'wdKit/Index';

/**
 * 接口数据存储工具类
 */
export class CacheDataSaveUtil {
  static save(key: string, value: string) {
    if (StringUtils.isEmpty(key)) {
      return
    }
    KVStoreHelper.default.put(key, value)
  }

  static get(key: string): Promise<string> {
    return new Promise<string>((success) => {
      if (StringUtils.isEmpty(key)) {
        success('')
      } else {
        KVStoreHelper.default.get(key, '').then((data) => {
          let str = data as string
          success(str)
        }).catch(() => {
          success('')
        })
      }
    })
  }
}