ts-prime
Version:
A utility library for JavaScript and Typescript.
24 lines • 905 B
TypeScript
export interface CacheMechanism<R> {
set: (key: string, data: R) => void;
get: (key: string) => R | undefined;
}
export declare type ArgsType<T> = T extends (...args: infer U) => any ? U : [];
export interface CacheOptions<I extends any[], R> {
cacheKeyFn?: (...args: I) => string;
cacheMechanism?: CacheMechanism<R>;
}
/**
* Function middleware that caches function output based on input
* @param fn - target function
* @param cacheFn - function that receives and return cache key
* @signature
* P.cache(fn, options)
* @signature
* P.cache(options)(fn)
* @example
* const request = (url: string) => axios.get(url)
* const requestWithCache = P.cache(request, (url) => url)
* @category Utility, Pipe
*/
export declare function cache<I extends (...args: any[]) => any>(fn: I, options?: CacheOptions<ArgsType<I>, ReturnType<I>>): I;
//# sourceMappingURL=cache.d.ts.map