Documentation / @andrew_l/toolkit / withCacheFixed
Function: withCacheFixed() ​
withCacheFixed<
T
>(__namedParameters
,fn
):WithCacheResult
<T
>
Wrap a function to cache results by arguments
But with capacity limitation
Type Parameters ​
T ​
T
extends AnyFunction
Parameters ​
__namedParameters ​
fn ​
T
Returns ​
Example ​
ts
const sum = withCacheFixed({ capacity: 1 }, (a, b) => {
console.log('calc?');
return a + b;
});
sum(1, 2); // calc?
sum(1, 2);
sum(1, 3) // calc?
sum(1, 3)
sum(1, 2); // calc?