fast-typescript-memoize
Version:
Fast memoization decorator and other helpers with 1st class support for Promises.
13 lines • 724 B
TypeScript
/**
* A simple intrusive 1-slot cache memoization helper for 2 parameters
* functions. It's useful when we have a very high chance of hit rate and is
* faster (and more memory efficient) than a Map<TArg1, Map<TArg2, TResult>>
* based approach since it doesn't create intermediate maps.
*
* This method works seamlessly for async functions too: the returned Promise is
* eagerly memoized, so all the callers will subscribe to the same Promise.
*
* Returns the new memoized function with 2 arguments for the `tag`.
*/
export declare function memoize2<TTag extends symbol, TArg1, TArg2, TResult>(obj: object, tag: TTag, func: (arg1: TArg1, arg2: TArg2) => TResult): typeof func;
//# sourceMappingURL=memoize2.d.ts.map