memoize-async
Async memoization
npm install memoize-async
API
memoize(fn: function [, keyGen: function]): Promise
- fn: function to evaluate (can be async or sync)
- keyGen: function used to generate a key from fn params, useful for complex memoization (can be async or sync)
memoize-async
expects the globalPromise
to be defined
Examples
Standard:
const fn = const memFetch = // must resolve from fn // resolves from cache
With KeyGen:
const fn = const keyGen = userid const memFetchUserProfile = const user = id: '1234-5678' profile: 'http://some.api/users/1234-5678' // sets cache key to '1234-5678' // resolves from cache
Clearing cache:
const url = 'http://some.api/things' const fn = const memFetch = const CLEAR_TIMER = 1000 * 60 * 5 // also
Testing
Run npm test
. To also generate coverage run npm run test:coverage
.