1.0.1 • Published 5 years ago
@skylab/lru v1.0.1
node-lru
A simple LRU (Least Recently Used) cache implementation.
What it does?
It takes a getter function as first argument and the size of cache (max key value pairs) as the second argument. The function is called when there is a cache miss.
Installation
foo@bar:src$ npm install @skylab/node-lru
Usage
function getValue(key){
//calculate or get value remotely query/db/ajax etc.
return value;
}
let LRU = require('@skylab/node-lru')
let cache = new LRU(getValue, 50);
const key = 10;
console.log(cache.get(10)); // getValue function is called to get value and stored in cache , if the cache is full the oldest accessed value is purged
console.log(cache.get(10)); // the value is retrieved from cache.
Alternatives
Todo
- Documentation
- Add Test