export type CacheKey = string; /** * Function to create cache key from params of the async function you want to cache */ export type CreateCacheKeyFn = (...params: Parameters) => CacheKey; type AsyncFn = (...params: any[]) => Promise; export type CreateCacheFn = (createCacheKey: CreateCacheKeyFn, options?: CacheOptions) => { withCache: (fn: AsyncFnToCache) => AsyncFnToCache; clearCache: (specificKey?: CacheKey) => void; }; type CacheOptions = { cacheMaxSize?: number; }; /** * Universal cache creator for any async function * * @param createCacheKey - function to create cache key from params of the async function you want to cache * @param options - optional object with cache options * @returns - object with two methods: withCache and clearCache. * "withCache" is a function that wraps the async function you want to cache. * "clearCache" is a function to clear the cache. * @example * const myAsyncFn = async (a: number, b: number) => a + b; * * // define here how to create cache-key for your function * const createExecuteQueryCacheKey: CreateCacheKeyFn = (a, b) => `${a}+${b}`; * * const { withCache, clearCache } = createCache(createExecuteQueryCacheKey); * const executeQueryWithCache = withCache(executeQuery); */ export declare const createCache: CreateCacheFn; export {};