Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
dataloader-cache-lru
Advanced tools
LRU (least recently used) cache for Facebook's DataLoader.
npm install dataloader-cache-lru --save
DataLoader, by default, uses the standard Map which simply grows until the DataLoader is released. The default is appropriate when requests to your application are short-lived.
Longer lived DataLoaders, such as ones which persist between GraphQL queries, will build up memory pressure unless the size of the cache is controlled. Furthermore, if records mutate, their cache entries must be removed.
This DataLoader-compatible cache implements a LRU (least recently used) cache, it deletes the least recently used items when the cache size is exceeded.
const DataLoader = require('dataloader');
const dataLoaderCacheLru = require('dataloader-cache-lru');
const cacheMap = dataLoaderCacheLru({ max: 3 }); // see options in isaacs/node-lru-cache
const dataloader = new DataLoader(batchLoadFn, { cacheMap });
Promise.all(
['a', 'b', 'c', 'd', 'e'].map(key => dataloader.load(key))
)
.then(data => {
console.log(data); // [{ key: 'a', data: 'a' }, ..., { key: 'e', data: 'e' }]
console.log(cacheMap.keys().sort()); // ['c', 'd', 'e']
});
// record with key 'd' has been mutated
dataloader.clear('d');
console.log(cacheMap.keys().sort()); // ['c', 'e']
function batchLoadFn (keys) {
return Promise.all(
keys.map(key => ({ key, data: key }))
);
}
Copyright (c) 2017
Licensed under the MIT license.
v1.0.1 (2017-10-02)
FAQs
LRU (least recently used) cache for Facebook's DataLoader.
We found that dataloader-cache-lru 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.