zyre-lru

1.0.4 • Public • Published

Zyre-LRU

ZRE enabled decentralised & distributed LRU Cache w/ TTL

Zyre-LRU will spawn multiple LRUs with set actions syncronized via whisper or shout

Usage

const ZDB = require('zyre-lru');

Peering

// Initialize peers
const db1 = new ZDB({ group: "lru1", size: 1024, discoveryPort: 4567, name: "LRU #1", auto: true });
const db2 = new ZDB({ group: "lru2", size: 1024, discoveryPort: 4567, name: "LRU #2", auto: true });
 
// Set Value
db1.set('test',123);
db1.get('test'); //should return 123
 
/* set action will propagate to all connected peers */
 
db2.get('test'); // should return 123
 
// Shutdown peers when done
db1.stop();
db2.stop();
 

LRU Commands

const ZDB = require('zyre-lru');
const cache = new ZDB({ group: "lru1", size: 1024, discoveryPort: 4567, name: "LRU #1", auto: true });
 
cache.set("item", 1, { ttl: 100 }); //-> Add item to cache (expire in 100ms).
 
cache.get("item"); //-> 1
cache.has("item"); //-> true
cache.expire("item", 50); //-> Expire in 50ms (instead of 100).
cache.delete("item"); //-> Delete item right away.
cache.clear(); //-> Empty the cache.
// You can also use the "refresh" option to automatically reset a keys expiration when accessed.
cache.set("item", 1, { ttl: 100, refresh: true });
// 50ms later
cache.get("item"); // Resets timer back to 100ms.
// And store meta data about values.
cache.set("item", 1, { meta: { custom: 1 } });
// Then retrieve it.
cache.meta("item"); //-> { custom: 1 }

Acknowledgement

Zyre-LRU is spinoff clone of zyre-nedb using zyre.js and receptacle

Package Sidebar

Install

npm i zyre-lru

Weekly Downloads

2

Version

1.0.4

License

BSD-3-Clause

Unpacked Size

10.5 kB

Total Files

8

Last publish

Collaborators

  • lmangani