export interface LSCache { version: string; data: { [uuid: string]: T; }; } export interface LSOptions> { /** 缓存文件保存的路径 */ filepath?: string; /** 缓存版本。当版本不匹配时将清空已有数据 */ version?: string; /** 存储类型的唯一标记,用于区分多个不同类型的存储。默认为 defaults */ uuid?: string; /** 默认初始值 */ initial?: T; /** 是否仅考虑单进程模式读写(内存)。默认为 false,每次保持前都会重载数据 */ singleMode?: boolean; } /** * 轻量的本地文件持久性数据存储。主要用于简单的配置信息持久化 * @example * ```ts * const stor = await new LiteStorage({ uuid: 'test1' }).ready(); * * // 示例1: 读取缓存 * const config = stor.get(); * console.log(config); * // 缓存操作 * // 存入 * stor.save(config); * * stor.getItem('key1'); * stor.setItem('key2', { a: 1 }); * stor.removeItem('key2'); * stor.clear(); * ``` */ export declare class LiteStorage> { private static instance; static getInstance(options?: LSOptions): LiteStorage; private get cachePath(); private barrier; private isToml; private isJson5; private isChanged; private cache; private options; private baseDir; constructor(options?: LSOptions); private init; get length(): number; get config(): { filepath: string; version: string; uuid: string; initial: Record; singleMode: boolean; }; ready(): Promise; /** 主动保存 */ save(value?: T, mode?: 'merge' | 'cover', reload?: boolean): Promise; private cacheTimer; private toCache; /** 从文件中重载数据至内存。在多进程、多线程模式下,需读取最新数据时,可手动调用 */ reload(): Promise; /** 以 options.uuid 为 key 设置数据 */ set(value: T, mode?: 'merge' | 'cover'): Promise; /** * 以 options.uuid 为 key 获取数据 * @param raw 是否返回原始数据(不进行深拷贝)。默认为 false */ get(raw?: boolean): T; /** 获取全量缓存的原始数据 */ getAll(): LSCache; /** 移除一项数据。同 removeItem 方法 */ del(key: keyof T): Promise; /** 设置并保存一个数据项。提示:setItem、removeItem 都会触发文件读写,应避免密集高频调用 */ setItem(key: K, value: T[K] extends object ? Partial : T[K], mode?: 'merge' | 'cover'): Promise; getItem(key: K): T[K]; /** 移除一项数据 */ removeItem(key: keyof T): Promise; /** * 清理缓存 * @param isAll 是否清空全部缓存(即移除缓存文件重新初始化)。默认为 false,只清空当前 uuid 约束下的缓存数据 */ clear(isAll?: boolean): Promise; }