
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.
lean-cache
Advanced tools
Lean and customizable in-memory cache. Allows to restrict cache in size as well as time. Provides different replacement strategies
const LeanCache = require('lean-cache');
// how to get new entry
const loadFunc = (id) => {
return db.fetch(id);
};
const opts = {
load: loadFunc,
};
const cache = new LeanCache(opts);
await cache.get('abc'); // Await is not needed if No Load Function was provided
cache.get('abc', function(err, value){
// either fetched from memory or via <loadFunc>
console.log('my value = %s', value);
});
// DEFAULT_OPTIONS
{
size: 100000, // 100k records max
ttl: (60 * 60), // 1 hour
interval: 600, // 10 minutes
strategy: 'fifo', // First in first out
storage: 'memory', // where to store cache objects
load: null, // Where to get missing data
}
| att | min | max | enum | comment |
|---|---|---|---|---|
| size | 0 | 5000000 | 5 mil | |
| ttl | 0 | 2592000 | 30 days | |
| interval | 0 | 86400 | 24 hours | |
| strategy | _ | _ | fifo, lru, none | more |
| storage | _ | _ | memory, file | more |
if availible - returns a value from cache, otherwise uses to fetch value (and stores it for next use)
explicitly set the tuple
returns amount of entries in the cache
{
"count": 0,
"strategy": "fifo",
"head": null, // Key, for FiFo - the Oldest entry
"headAdded": null, // Timestamp
"tail": null, // Key, for FiFo - the Newest entry
"tailAdded": null, // Timestamp
"lastInterval": "2019-01-21T07:56:55.638Z", // Timestamp, when last check happened
"lastExpiredCount": 5, // Number, how many entries were removed during the last check
"lastExpiredAdded": "2019-01-21T07:56:52.642Z",
"lastExpiredRemoved": "2019-01-21T07:56:55.638Z"
}
Array of availible keys
custom strategy
// Demonstrates "None" strategy - when <count> exceeds <size>, returns False
const custom = function(opts, storage){
this.opts = opts;
const store = storage;
this.set = function(key, obj){
if(store.count() >= this.opts.size){
return false; //deny
}
// add to Tail
store.add(key, obj);
return true;
};
this.get = function(key){
return store.get(key);
};
};
const cache = new LeanCache({size:1, strategy:custom});
cache.set('a', {}); //true
cache.set('b', {}); //false
cache.keys(); // ['a']
Debugging is done via "debug" library, add ENV variable to enable.
DEBUG=lean-cache node your-very-cool-app.js
$ node --expose-gc benchmark/storageLoad.js
// benchmark - simple array
// n - amount of operations
*** Start - storageLoad.js ***
>>> TimeAdd - benchmark - n = 1000000 | t = 192 ms | mem = 77.09 mb
>>> TimeAdd - storage - n = 1000000 | t = 1028 ms | mem = 306.25 mb
add = -836
>>> TimeRead - benchmark - n = 500000 | t = 3 ms | mem = 306.28 mb
>>> TimeRead - storage - n = 500000 | t = 162 ms | mem = 307.38 mb
read = -159
>>> TimeDelete - benchmark - n = 1000 | t = 1441 ms | mem = 307.39 mb
>>> TimeDelete - storage - n = 1000 | t = 1 ms | mem = 307.4 mb
del = 1440
On avg the storage is Ahead by = 148.33 ms
>>> Garbage collector - mem = 275.74 mb
*** Start - storageLoad.js ***
>>> TimeAdd - benchmark - n = 1000000 | t = 179 ms | mem = 81.2 mb
>>> TimeAdd - storage - n = 1000000 | t = 1096 ms | mem = 309.46 mb
add = -917
>>> TimeRead - benchmark - n = 500000 | t = 3 ms | mem = 309.49 mb
>>> TimeRead - storage - n = 500000 | t = 158 ms | mem = 310.13 mb
read = -155
>>> TimeDelete - benchmark - n = 1000 | t = 1399 ms | mem = 310.14 mb
>>> TimeDelete - storage - n = 1000 | t = 1259 ms | mem = 310.15 mb
del = 140
On avg the storage is Ahead by = -310.67 ms
>>> Garbage collector - mem = 270.53 mb
FAQs
Lean and customizable in-memory cache
We found that lean-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.