
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
locking-cache
Advanced tools
I am a locking LRU cache. This means that subsequent calls to a cached function will wait until the initial call has populated the cache, at which point all pending calls will be provided with cached data.
var lockingCache = require("locking-cache"),
lockedFetch = lockingCache({
// lru-cache options
max: 10
});
var fetch = lockedFetch(function(uri, lock) {
// generate a key
var key = uri;
// lock
return lock(key, function(unlock) {
// make the call that produces data to be cached
return request.get(uri, function(err, rsp, body) {
// optionally do stuff to data that's been returned
// unlock, caching non-error arguments
// all arguments will be passed to pending callbacks
return unlock(err, rsp, body);
});
});
});
// will trigger the initial fetch
fetch("http://google.com/", function(err, rsp, body) {
// ...
// rsp and body will be returned from the cache
// if evicted, a fetch will be triggered again
fetch("http://google.com/", function(err, rsp, body) {
///
});
});
// will wait for the initial fetch to complete (or fail)
fetch("http://google.com/", function(err, rsp, body) {
// ...
});
See lru-cache for cache options.
The dispose option that's passed to the underlying LRU differs slightly from
what lru-cache documents, as values are stored as arrays in order to support
varargs (multiple values passed to unlock()):
var lockedFetch = lockingCache({
dispose: function(key, values) {
// ...
});
A custom factory function (that returns an LRU instance or compatible) may be
provided as the last argument. Here are 2 examples of how it can be used.
var lockingCache = require("locking-cache"),
lockedFetchA = lockingCache(function() {
return LRU({
max: 10
});
}),
lockedFetchB = lockingCache({
name: "B",
max: 10
}, function(options) {
console.log("Creating cache for %s", options.name);
return LRU(options);
});
// ...
FAQs
A locking LRU cache
The npm package locking-cache receives a total of 65 weekly downloads. As such, locking-cache popularity was classified as not popular.
We found that locking-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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.