JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 919251
  • Score
    100M100P100Q184675F
  • License MIT

Memoize promise-returning & async functions

Package Exports

  • p-memoize

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (p-memoize) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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(input, [options])

Returns a memoized version of the input function.

input

Type: Function

Promise-returning or async function to be memoized.

options

Type: Object

See the mem options.

pMemoize.clear(fn)

Clear all cached data of a memoized function.

License

MIT © Sindre Sorhus