Gathering detailed insights and metrics for p-memoize
Gathering detailed insights and metrics for p-memoize
Gathering detailed insights and metrics for p-memoize
Gathering detailed insights and metrics for p-memoize
p-memoize-cjs
Compilation of p-memoize to cjs to avoid needing to run ESM
@typedash/p-memoize
CJS copy of p-memoize
@rebundled/p-memoize
Memoize promise-returning & async functions
@types/p-memoize
Stub TypeScript definitions entry for p-memoize, which provides its own types definitions
npm install p-memoize
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.3
Supply Chain
99.5
Quality
78.2
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
407 Stars
50 Commits
31 Forks
7 Watchers
1 Branches
14 Contributors
Updated on May 21, 2025
Latest Version
7.1.1
Package Id
p-memoize@7.1.1
Unpacked Size
15.86 kB
Size
4.83 kB
File Count
5
NPM Version
8.3.2
Node Version
14.19.3
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Memoize promise-returning & async functions
Useful for speeding up consecutive function calls by caching the result of calls with identical input.
By default, only the memoized function's first argument is considered via strict equality comparison. If you need to cache multiple arguments or cache object
s by value, have a look at alternative caching strategies below.
This package is similar to mem but with async-specific enhancements; in particular, it allows for asynchronous caches and does not cache rejected promises.
1npm install p-memoize
1import pMemoize from 'p-memoize'; 2import got from 'got'; 3 4const memoizedGot = pMemoize(got); 5 6await memoizedGot('https://sindresorhus.com'); 7 8// This call is cached 9await memoizedGot('https://sindresorhus.com');
Similar to the caching strategy for mem
with the following exceptions:
cache
. Special properties assigned to a returned promise will not be kept after resolution and every promise may need to resolve with a serializable object if caching results in a database..get()
, .has()
and .set()
methods on cache
can run asynchronously by returning a promise..set()
being provided an object with the properties value
and maxAge
, it will only be provided value
as the first argument. If you want to implement time-based expiry, consider doing so in cache
.Returns a memoized version of the given function.
Type: Function
Promise-returning or async function to be memoized.
Type: object
Type: Function
Default: arguments_ => arguments_[0]
Example: arguments_ => JSON.stringify(arguments_)
Determines the cache key for storing the result based on the function arguments. By default, only the first argument is considered.
A cacheKey
function can return any type supported by Map
(or whatever structure you use in the cache
option).
See the caching strategy section for more information.
Type: object | false
Default: new Map()
Use a different cache storage. Must implement the following methods: .has(key)
, .get(key)
, .set(key, value)
, .delete(key)
, and optionally .clear()
. You could for example use a WeakMap
instead or quick-lru
for a LRU cache. To disable caching so that only concurrent executions resolve with the same value, pass false
.
See the caching strategy section in the mem
package for more information.
Returns a decorator to memoize class methods or static class methods.
Notes:
--experimentalDecorators
; follow TypeScript’s docs.Type: object
Same as options for pMemoize()
.
1import {pMemoizeDecorator} from 'p-memoize'; 2 3class Example { 4 index = 0 5 6 @pMemoizeDecorator() 7 async counter() { 8 return ++this.index; 9 } 10} 11 12class ExampleWithOptions { 13 index = 0 14 15 @pMemoizeDecorator() 16 async counter() { 17 return ++this.index; 18 } 19}
Clear all cached data of a memoized function.
It will throw when given a non-memoized function.
1import pMemoize from 'p-memoize'; 2import ExpiryMap from 'expiry-map'; 3import got from 'got'; 4 5const cache = new ExpiryMap(10000); // Cached values expire after 10 seconds 6 7const memoizedGot = pMemoize(got, {cache});
1import pMemoize from 'p-memoize';
2import pReflect from 'p-reflect';
3
4const memoizedGot = pMemoize(async (url, options) => pReflect(got(url, options)));
5
6await memoizedGot('https://example.com');
7// {isFulfilled: true, isRejected: false, value: '...'}
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 14/30 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More