Installations
npm install async-memoize-one
Score
82.9
Supply Chain
93.9
Quality
77.6
Maintenance
100
Vulnerability
100
License
Developer
microlinkhq
Developer Guide
Module System
CommonJS
Min. Node Version
>= 12
Typescript Support
No
Node Version
20.12.2
NPM Version
10.5.0
Statistics
29 Stars
41 Commits
5 Forks
2 Watching
1 Branches
2 Contributors
Updated on 07 Sept 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
815,539
Last day
-34.1%
1,345
Compared to previous day
Last week
5.1%
7,826
Compared to previous week
Last month
97%
27,832
Compared to previous month
Last year
-13.9%
206,113
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Memoize the last result, in async way.
async-memoize-one simply remembers the last arguments, and if the function is next called with the same arguments then it returns the previous result.
It's used for micro-caching scenarios, where you want to prevent perform an action previously done during a short period of time.
No need to worry about cache busting mechanisms such as maxAge, maxSize, exclusions and so on which can be prone to memory leaks.
Install
1$ npm install async-memoize-one --save
Usage
1const get = require('util').promisify(require('simple-get')) 2const memoizeOne = require('async-memoize-one') 3 4const fetchData = memoizeOne(url => get(`https://api.microlink.io?url=${url}`)) 5 6;(async () => { 7 // fecthing data for first time 8 console.time('fetch') 9 await fetchData('https://example.com/one') 10 console.timeEnd('fetch') 11 12 // served data from cache; no fetching! 13 console.time('fetch') 14 await fetchData('https://example.com/one') 15 console.timeEnd('fetch') 16 17 // previous execution parameters are different, so fetching again 18 console.time('fetch') 19 await fetchData('https://example.com/two') 20 console.timeEnd('fetch') 21 22 // previous execution parameters are different, so fetching again 23 console.time('fetch') 24 await fetchData('https://example.com/one') 25 console.timeEnd('fetch') 26})()
API
memoizeOne(fn, [isEqual], [options])
fn
Required
Type: function
Promise-returning or async function to be memoized.
isEqual
Type: function
Default: fast-deep-equal
The compare function to determinate if both executions are the same.
An equality function should return true if the arguments are equal. If true is returned then the wrapped function will not be called.
options
cachePromiseRejection
Type: boolean
Default: false
Cache rejected promises.
License
async-memoize-one © microlink.io, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.
microlink.io · GitHub microlink.io · Twitter @microlinkhq
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.md:0
Reason
Found 1/20 approved changesets -- score normalized to 0
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
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/microlinkhq/async-memoize-one/main.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/microlinkhq/async-memoize-one/main.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/microlinkhq/async-memoize-one/main.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/microlinkhq/async-memoize-one/main.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 11 are checked with a SAST tool
Score
3.4
/10
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 MoreOther packages similar to async-memoize-one
memoize-one
A memoization library which only remembers the latest invocation
p-memoize
Memoize promise-returning & async functions
@formatjs/fast-memoize
fork of fast-memoize and support esm
memoize
Memoize functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input