/p-memoize

Memoize promise-returning & async functions

Primary LanguageJavaScriptMIT LicenseMIT

p-memoize Build Status

Memoize promise-returning & async functions

Useful for speeding up consecutive function calls by caching the result of calls with identical input.

Install

$ npm install --save p-memoize

Usage

const pMemoize = require('p-memoize');
const got = require('got');
const memGot = pMemoize(got, {maxAge: 1000});

memGot('sindresorhus.com').then(() => {
	// this call is cached
	memGot('sindresorhus.com').then(() => {
		setTimeout(() => {
			// this call is not cached as the cache has expired
			memGot('sindresorhus.com').then(() => {});
		}, 2000);
	});
});

API

See the mem docs.

The only difference is that this module does not cache rejected promises.

Related

License

MIT © Sindre Sorhus