2.0.0 • Published 1 year ago
@checkdigit/memoize v2.0.0
Memoize
Copyright (c) 2023–2024 Check Digit, LLC
@checkdigit/memoize
memoizes async functions, with cache eviction on reject.
The resulting promise is cached, guaranteeing the underlying function is called at most once for a given set of
arguments, unless the promise ultimately rejects.
If the promise is rejected, it will be removed from the memoize cache.
This allows the function to be retried.
Install
$ npm install @checkdigit/memoize
Use
import memoize from '@checkdigit/memoize';
async function doIt(parameter: number): Promise<number> {
console.log('doing it', parameter); // doing it 123, doing it 456 (note parameter=123 only executed once)
return parameter * 2;
}
const memoizedDoIt = memoize(doIt);
const value1 = await memoizedDoIt(123);
const value2 = await memoizedDoIt(456);
const value3 = await memoizedDoIt(123); // uses cached result
console.log('the results were', value1, value2, value3); // the results were 246 912 246
License
MIT
2.0.0
1 year ago
2.0.0-PR.9-d626
1 year ago
2.0.0-PR.9-d49e
1 year ago
1.1.0
2 years ago
1.1.0-PR.4-dcc8
2 years ago
1.1.0-PR.4-f737
2 years ago
1.1.0-PR.4-45af
2 years ago
1.1.0-PR.4-b1c7
2 years ago
1.1.0-PR.4-45eb
2 years ago
1.1.0-PR.4-87e1
2 years ago
1.1.0-PR.4-1eae
2 years ago
1.1.0-PR.4-e63d
2 years ago
1.1.0-PR.4-4268
2 years ago
1.1.0-PR.4-a793
2 years ago
1.1.0-PR.4-d02c
2 years ago
1.1.0-PR.4-f8a0
2 years ago
1.1.0-PR.4-1a1b
2 years ago
1.0.0-PR.4-a69b
2 years ago
1.0.0
2 years ago
1.0.0-PR.2-7535
2 years ago
1.0.0-PR.2-8d1d
2 years ago
1.0.0-PR.2-be97
2 years ago
1.0.0-PR.2-2998
2 years ago
1.0.0-PR.2-dcd9
2 years ago
1.0.0-PR.2-665a
2 years ago