Skip to content

ZRE enabled decentralized and distributed LRU Cache w/ TTL

License

Notifications You must be signed in to change notification settings

lmangani/zyre-lru

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zyre-LRU

ZRE enabled decentralised & distributed LRU Cache w/ TTL

Zyre-LRU will spawn multiple LRUs discovering each other and syncronizing cache set actions via ZRE whisper

ezgif com-optimize 49

LRU Cache entries can store and distribute Text, JSON or Binary payloads with optional TTL expiration


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 }

Project Status

  • Experimental! Use at your own risk!
  • PRs and Ideas are highly welcome!

Acknowledgement

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

Releases

No releases published

Sponsor this project

 

Packages

No packages published