3.1.0-PR.13-800f • Published 1 year ago

@checkdigit/memoize v3.1.0-PR.13-800f

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Memoize

Copyright (c) 2023–2025 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

3.1.0

1 year ago

3.0.0

1 year ago

2.0.0

2 years ago

2.0.0-PR.9-d626

2 years ago

2.0.0-PR.9-d49e

2 years ago

1.1.0

3 years ago

1.1.0-PR.4-dcc8

3 years ago

1.1.0-PR.4-f737

3 years ago

1.1.0-PR.4-45af

3 years ago

1.1.0-PR.4-b1c7

3 years ago

1.1.0-PR.4-45eb

3 years ago

1.1.0-PR.4-87e1

3 years ago

1.1.0-PR.4-1eae

3 years ago

1.1.0-PR.4-e63d

3 years ago

1.1.0-PR.4-4268

3 years ago

1.1.0-PR.4-a793

3 years ago

1.1.0-PR.4-d02c

3 years ago

1.1.0-PR.4-f8a0

3 years ago

1.1.0-PR.4-1a1b

3 years ago

1.0.0-PR.4-a69b

3 years ago

1.0.0

3 years ago

1.0.0-PR.2-7535

3 years ago

1.0.0-PR.2-8d1d

3 years ago

1.0.0-PR.2-be97

3 years ago

1.0.0-PR.2-2998

3 years ago

1.0.0-PR.2-dcd9

3 years ago

1.0.0-PR.2-665a

3 years ago