Skip to content
Memoize promise-returning & async functions
JavaScript TypeScript
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig Require Node.js 6 and meta tweaks (#4) May 25, 2018
.gitattributes Add `pMemoize.clear()` method May 25, 2018
.gitignore Add `pMemoize.clear()` method May 25, 2018
.npmrc
.travis.yml Require Node.js 6 and meta tweaks (#4) May 25, 2018
index.d.ts Minor TypeScript definition tweak Jun 7, 2019
index.js
index.test-d.ts Refactor TypeScript definition to CommonJS compatible export (#8) Apr 5, 2019
license Require Node.js 6 and meta tweaks (#4) May 25, 2018
package.json 3.1.0 Apr 5, 2019
readme.md Meta tweaks Mar 13, 2019
test.js Meta tweaks Mar 13, 2019

readme.md

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 p-memoize

Usage

const pMemoize = require('p-memoize');
const got = require('got');

const memGot = pMemoize(got, {maxAge: 1000});

(async () => {
	memGot('sindresorhus.com');

	// This call is cached
	memGot('sindresorhus.com');

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

API

pMemoize(fn, [options])

Returns a memoized version of the fn function.

fn

Type: Function

Promise-returning or async function to be memoized.

options

Type: Object

See the mem options.

pMemoize.clear(memoized)

Clear all cached data of a memoized function.

Will throw if passed a non-memoized function.

Related

License

MIT © Sindre Sorhus

You can’t perform that action at this time.