2.0.0 • Published 1 month ago

@checkdigit/memoize v2.0.0

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

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 month ago

2.0.0-PR.9-d626

1 month ago

2.0.0-PR.9-d49e

1 month ago

1.1.0

9 months ago

1.1.0-PR.4-dcc8

9 months ago

1.1.0-PR.4-f737

9 months ago

1.1.0-PR.4-45af

9 months ago

1.1.0-PR.4-b1c7

9 months ago

1.1.0-PR.4-45eb

9 months ago

1.1.0-PR.4-87e1

9 months ago

1.1.0-PR.4-1eae

9 months ago

1.1.0-PR.4-e63d

9 months ago

1.1.0-PR.4-4268

9 months ago

1.1.0-PR.4-a793

9 months ago

1.1.0-PR.4-d02c

9 months ago

1.1.0-PR.4-f8a0

9 months ago

1.1.0-PR.4-1a1b

9 months ago

1.0.0-PR.4-a69b

9 months ago

1.0.0

11 months ago

1.0.0-PR.2-7535

11 months ago

1.0.0-PR.2-8d1d

11 months ago

1.0.0-PR.2-be97

11 months ago

1.0.0-PR.2-2998

11 months ago

1.0.0-PR.2-dcd9

11 months ago

1.0.0-PR.2-665a

11 months ago