Skip to content

Documentation / @andrew_l/toolkit / withCacheLRU

Function: withCacheLRU() ​

withCacheLRU<T>(__namedParameters, fn): WithCacheResult<T>

Wrap a function to cache results by arguments

But with LRU

Type Parameters ​

T ​

T extends AnyFunction

Parameters ​

__namedParameters ​

WithCacheLruOptions

fn ​

T

Returns ​

WithCacheResult<T>

Example ​

ts
const sum = withCacheLRU({ capacity: 100 }, (a, b) => {
    console.log('calc?');
    return a + b;
});

sum(1, 2); // calc?
sum(1, 2);