distributed LRU cache
const Cache = require('disributed-lru-cache');
//distributed lru cache uses rabbitmq for sync cache across different instances
let cache = new Cache(brokerURL); // cache instance
//sets a value in cache with 'a' as key and 1 as value
cache.set('a', 1);
cache.set('b', 2);
cache.set('c', 3);
/*
[ { key: 'a', value: 1 },
{ key: 'b', value: 2 },
{ key: 'c', value: 3 } ]
*/
cache.get('c') //returns 3 and makes it most recently used
/*
[ { key: 'c', value: 3 },
[ { key: 'a', value: 1 },
{ key: 'b', value: 2 } ]
*/
cache.peek('a') //returns 1 but doesnt resets the order
/*
[ { key: 'c', value: 3 },
{ key: 'a', value: 1 },
{ key: 'b', value: 2 } ]
*/
cache.has('z') // returns boolean
//Initialize Cache that expires in 3 hours
let cache = new Cache(brokerURL, 3);
brokerURL
Type: ‘string’
rabbitmq broker url
expireIn
Type: number
default: Infinity