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
npm install p-memoize
99
Supply Chain
99.5
Quality
78.2
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
396 Stars
50 Commits
30 Forks
8 Watching
1 Branches
14 Contributors
Updated on 15 Nov 2024
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
-27.9%
176,469
Compared to previous day
Last week
-0.3%
1,192,347
Compared to previous week
Last month
3.2%
4,899,821
Compared to previous month
Last year
31.6%
46,292,576
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 binaries found in the repo
Reason
no dangerous workflow patterns detected
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
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
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 2024-11-18
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