I need to implement caching for my project(for my organisation), we are planing to have a in-memory LRU caching, I have got some packages but I am not sure about the licensing term, the best I found was this
https://www.npmjs.com/package/lru-cache
but here I am facing some issues when I declare my cache as
var LRU = require("lru-cache")
, options = { max: 2
, length: function (n, key) { return n * 2 + key.length }
, dispose: function (key, n) { n.close() }
, maxAge: 1000 * 60 * 60 }
, cache = LRU(options)
console.log(cache.length)
cache.set(1,1)
cache.set(2,2)
cache.set(3,3)
console.log(cache.length)
console.log(cache.get(1))
console.log(cache.get(2))
console.log(cache.get(3))
console.log(cache)
The output which I get for above code is
0
NaN
1
2
3
LRUCache {}
It doesn't set the max value and it's seems to be infinity Even If the length is 2 it is not removing the LRU element and adding all three element in the cache
Is any other package available ?, I am also thinking to implement my own caching mechanism, what is the best practice for node js.