
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
lru-cache-node
Advanced tools
A lighting fast cache manager for node with least-recently-used policy.
A lighting fast cache manager for node with least-recently-used policy.
A super fast cache for node with LRU policy. Cache will keep on adding values until the maxSize is reached.
After that it will start popping out the Least recently used/accessed value from the cache in order to set the new ones.
Supports expiry and stale.
Implemented using doubly-linked-list and hashmap with O(1) time complexity for gets and sets.
$ npm install --save lru-cache-node
const Cache = require('lru-cache-node');
let cache = new Cache(3); //set max size of cache as three
cache.set('a', 7); //sets a value in cache with 'a' as key and 7 as value
cache.set('b', 5);
cache.set('c', 3);
/*
[ { key: 'c', value: 3 },
{ key: 'b', value: 5 },
{ key: 'a', value: 7 } ]
*/
cache.set('d', 10) // pops out a
/*
[ { key: 'd', value: 10 },
{ key: 'c', value: 3 },
{ key: 'b', value: 5 } ]
*/
cache.get("b") //returns 5 and makes it most recently used
/*
[ { key: 'b', value: 5 },
{ key: 'd', value: 10 },
{ key: 'c', value: 3 } ]
*/
cache.peek("d") //returns 10 but doesnt resets the order
/*
[ { key: 'b', value: 5 },
{ key: 'd', value: 10 },
{ key: 'c', value: 3 } ]
*/
let cache = new Cache(3, 10); //Initialize Cache with size 3 and expiry for keys as 10ms
const sleep = ms => new Promise(r => setTimeout(r, ms));
cache.set('a', 7); //valid for 10ms
cache.get('a'); //returns 7 and resets 10ms counter
await sleep(15);
cache.get('a'); //null
cache.set('b', 5, 30); //overwrites cache's default expiry of 10ms and uses 30ms
await sleep(15);
cache.get('b'); //returns 5 and resets the expiry of b back to 30ms
await sleep(35);
cache.get('b'); //null
maxSizeType: Number
Default: Infinity
Maximum size of the cache.
maxAgeType: Number
Default: Infinity
Default expiry for all keys for the cache. It does not proactively deletes expired keys, but will return null when an expired key is being accessed.
staleType: Boolean
Default: false
If set to true, will return the value of expired key before deleting it from cache.
keyKey to be set.
valueValue for the key.
maxAgeExpiry of the key. Will override cache's maxAge if specified.
Returns the value for the key. If not key does not exist will return null.
Both set() and get() will update the "recently used"-ness and expiry of the key.
Returns the value for the key, without making the key most recently used. If not key does not exist will return null.
Deletes the key from the cache.
Returns a boolean indication if the value exists in cache or not.
Alias for contains function.
Returns the current size of cache.
Clears the whole cache and reinitialize it.
Returns an array form of the catch.
let cache = new Cache();
cache.set("a", 5);
cache.set("b", 4);
cache.set("c", 0);
cache.toArray()
/*
[ { key: 'c', value: 0 },
{ key: 'b', value: 4 },
{ key: 'a', value: 5 } ]
*/
Takes a function and iterates over all the keys in the cache, in order of recentness. Callback takes key, value and index as params.
let cache = new Cache();
cache.set("a", 1);
cache.set("b", 2);
cache.set("c", 3);
cache.forEach((key, value, index) => {
console.log(key, value, index)
})
/*
c 3 0
b 2 1
a 1 2
*/
FAQs
A lighting fast cache manager for node with least-recently-used policy.
The npm package lru-cache-node receives a total of 670 weekly downloads. As such, lru-cache-node popularity was classified as not popular.
We found that lru-cache-node 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
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.