import { Cache } from "cache"; import { ClientResponseType } from "client"; import { CommandResponseDetails } from "managers"; export type CacheOptionsType = { /** * Assign your custom sync storage */ storage?: CacheStorageType; /** * Lazy loading from remote resources - possibly persistent */ lazyStorage?: CacheAsyncStorageType; /** * Key to clear lazy storage data */ clearKey?: string; /** * Initialization callback */ onInitialization?: (cache: Cache) => void; /** * Callback for every change in the storage */ onChange?: (key: string, data: CacheValueType) => void; /** * Callback for every delete in the storage */ onDelete?: (key: string) => void; }; // Values export type CacheValueType = { data: ClientResponseType; details: CommandResponseDetails; cacheTime: number; clearKey: string; }; // Storage export type CacheAsyncStorageType = { set: (key: string, data: CacheValueType) => Promise; get: (key: string) => Promise | undefined>; keys: () => Promise | string[]>; delete: (key: string) => Promise; }; export type CacheStorageType = { set: (key: string, data: CacheValueType) => void; get: (key: string) => CacheValueType | undefined; keys: () => string[] | IterableIterator | string[]; delete: (key: string) => void; clear: () => void; }; export type CacheInitialData = Record;