import Storage, { LoadParams } from 'react-native-storage'; import AsyncStorage from '@react-native-async-storage/async-storage'; export const storageApp = new Storage({ size: 1000, storageBackend: AsyncStorage, defaultExpires: 1000 * 3600 * 24 * 60, enableCache: true, }); /** * 缓存一个键值对 * @param key * @param value */ export const saveItem = (key: string, value: any) => storageApp.save({ key, data: value }); /** * 获取一个键值对 * @param key */ export const getItem = (key: string) => storageApp.load({ key, autoSync: true, syncInBackground: true }); /** * 删除一个键值对 * @param key */ export const removeItem = (key: string) => storageApp.remove({ key }); /** * 获取批量键值对 * @param params */ export const getAllItems = (params: LoadParams[]) => storageApp.getBatchData(params); export const saveAllItems = ( params: { key: string; id?: string; data: any; expires?: number | null; }[], ) => Promise.all([params.map(item => storageApp.save(item))]); export const removeAllItems = (params: string[]) => Promise.all([params.map(item => storageApp.remove({ key: item }))]);