
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
p-async-cache
Advanced tools
Cache the promise lookups and avoid fetching the same thing more than necessary
Cache the promise lookups and avoid fetching the same thing more than necessary.
$ npm install p-async-cache --save
import PAC from 'p-async-cache'
let counter = 0
const cache = new PAC({
async load (userId) {
counter ++
return await getUserFromRemote(userId)
}
})
function get () {
cache.get(123).then(({value}) => {
console.log(value, counter)
})
}
get()
get()
// [object User] 1
// [object User] 1 (The counter still be 1)
Object=
Boolean
whether allow stale valuefunction()=JSON.stringify
method to serialize the params
to a cache key.AsyncFunction(...params)|function(...params):Promise|function(...params)
accepts a normal synchronous function, a function that returns a promise, or an async function, and the params
will be the parameters of the .get(...params)
method.options.stale
import delay from 'delay'
const cache = new AC({
stale: true,
maxAge: 100,
load (a, b) {
return delay(1).then(() => a + b)
}
})
cache.get(1, 2)
.then(({value, stale}) => {
console.log(value) // 3
console.log(stale) // false
// Delay a timespan which is bigger than `maxAge`
return delay(101).then(() => cache.get(1, 2))
})
.then(({value, stale}) => {
console.log(value) // 3
console.log(stale) // true (the value is stale)
return delay(10).then(() => cache.get(1, 2))
})
.then(({value, stale}) => {
console.log(value) // 3
console.log(stale) // false (if the value is found as stale, it will refresh the value in the background)
})
any
that will be passed into options.load(...params)
Returns Promise
Lookup the value in the cache,
load(...params)
lru-cache
.reset()
.has(...params)
.peek(...params)
.del(...params)
MIT
FAQs
Cache the promise lookups and avoid fetching the same thing more than necessary
The npm package p-async-cache receives a total of 5,480 weekly downloads. As such, p-async-cache popularity was classified as popular.
We found that p-async-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.