Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
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 jslrucache = require('js-lrucache');
let cache = new jslrucache.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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.