Socket
Socket
Sign inDemoInstall

p-memoize

Package Overview
Dependencies
5
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    p-memoize

Memoize promise-returning & async functions


Version published
Maintainers
1
Install size
40.2 kB
Created

Readme

Source

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.

  • p-debounce - Debounce promise-returning & async functions
  • p-throttle - Throttle promise-returning & async functions
  • More…

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 05 Apr 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc