zyre-lru

ZRE enabled decentralized and distributed LRU Cache w/ TTL

Usage no npm install needed!

<script type="module">
  import zyreLru from 'https://cdn.skypack.dev/zyre-lru';
</script>

README

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