@boost/decorators
Version:
Experimental decorators for common patterns.
26 lines • 1.06 kB
TypeScript
export type MemoizedFunction<T> = (...args: unknown[]) => T;
export type MemoizeHasher = (...args: unknown[]) => string;
export type MemoizeCache<T> = Map<string, {
time?: number | null;
value: T;
}>;
export interface MemoizeOptions<T> {
/** A custom `Map` instance to store cached values. Can also be used to pre-cache expected values. */
cache?: MemoizeCache<T> | null;
/**
* Time in milliseconds in which to keep the cache alive (TTL).
* Pass `0` to cache indefinitely. Defaults to `0`.
*/
expires?: number;
/**
* A hashing function to determine the cache key. Is passed the method's arguments
* and must return a string. If not provided, arguments are hashed using `JSON.stringify()`.
*/
hasher?: MemoizeHasher;
}
/**
* A method decorator that caches the return value of a class method or
* getter to consistently and efficiently return the same value.
*/
export declare function Memoize<T>(options?: MemoizeHasher | MemoizeOptions<T>): MethodDecorator;
//# sourceMappingURL=Memoize.d.ts.map