Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lmangani/zyre-lru

ZRE enabled decentralized and distributed LRU Cache w/ TTL
https://github.com/lmangani/zyre-lru

cache discovery distributed lru peer-to-peer zeromq zre

Last synced: about 2 months ago
JSON representation

ZRE enabled decentralized and distributed LRU Cache w/ TTL

Awesome Lists containing this project

README

        

# Zyre-LRU
[ZRE](https://rfc.zeromq.org/spec:20/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](https://user-images.githubusercontent.com/1423657/38445147-8e548108-39f2-11e8-8d0a-2b973070c50a.gif)

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

--------------

### Usage
```javascript
const ZDB = require('zyre-lru');
```

#### Peering
```javascript
// 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
```javascript
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](https://github.com/arcoirislabs/zyre-nedb) using [zyre.js](https://github.com/interpretor/zyre.js) and [receptacle](https://github.com/DylanPiercey/receptacle)