Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
js-lrucache
Advanced tools
least recently used cache implemented using ES6 and Babel
Run the following command:
npm install js-lrucache
Below are the ES6 code demo:
import LRUCache from 'js-lrucache';
let cache = new LRUCache(4); // max capacity is 4
cache.put('a', { value: 1 });
cache.put('b', { value: 2 });
cache.put('c', { value: 3 });
cache.put('d', { value: 4 });
console.log(cache.size()); // display 4
cache.put('e', { value: 5 }); // 'a' gets removed as capacity is only 4 and 'a' is the oldest item stored
console.log(cache.size()); // display 4;
console.log(cache.get('a')); // display undefined as cache now contains only 'b', 'c', 'd', 'e'
cache.get('b'); // 'b' has been access recently
cache.put('f', { value: 6 }); // 'c' gets removed as 'b' access more recently than 'c'
console.log(cache.get('b')); // display { value: 2 }
console.log(cache.get('c')); // display undefined as 'c' has been removed
let cache2 = cache.deepCopy();
console.log(cache2.get('b')); // display { value: 2 }
Below are the Javascript code demo:
var LRUCache = require('js-lrucache').default;
let cache = new LRUCache(4); // max capacity is 4
cache.put('a', { value: 1 });
cache.put('b', { value: 2 });
cache.put('c', { value: 3 });
cache.put('d', { value: 4 });
console.log(cache.size()); // display 4
cache.put('e', { value: 5 }); // 'a' gets removed as capacity is only 4 and 'a' is the oldest item stored
console.log(cache.size()); // display 4;
console.log(cache.get('a')); // display undefined as cache now contains only 'b', 'c', 'd', 'e'
cache.get('b'); // 'b' has been access recently
cache.put('f', { value: 6 }); // 'c' gets removed as 'b' access more recently than 'c'
console.log(cache.get('b')); // display { value: 2 }
console.log(cache.get('c')); // display undefined as 'c' has been removed
let cache2 = cache.deepCopy();
console.log(cache2.get('b')); // display { value: 2 }
FAQs
Javascript implementation of least recently used cache
The npm package js-lrucache receives a total of 2 weekly downloads. As such, js-lrucache popularity was classified as not popular.
We found that js-lrucache 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
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.