0.1.5 • Published 6 months ago
distri-lru v0.1.5
distri-lru
A library for geo-distributed LRU cache with real-time replication
Requirements
Need to have cache servers setup as according to: https://github.com/t2pellet/distri-lru-server
Install
Needs axios
installed as peer dependency
yarn add distri-lru
Usage
import DistributedLRUCache from 'distri-lru';
const cacheNodes: CacheMap = [
{ loc: [40.7128, 74.0060], cache: { host: '127.0.0.1', port: '6379' } },
{ loc: [52.52, 13.405], cache: { host: '127.0.0.1', port: '6380' } },
{ loc: [29.3117, 47.4818], cache: { host: '127.0.0.1', port: '6381' } }
]
const dCache = new DistributedLRUCache(cacheNodes);
dCache.put('key', { value: '123' }, { ip: '45.67.89.0', ttl: 60 });
Methods
put(key: string, val: object, options: { ip?: string, ttl?: number }): Promise<boolean>
get(key: string, options: { ip?: string }): Promise<object | undefined | null>
del(key: string, options: { ip?: string }): Promise<boolean>
for(ip: string): Promise<CacheInterface | null>
CacheInterface
is the same but without the need for IP
Features
- LRU cache with put / get / del methods
- Accesses closest cache geographically to the IP
- Realtime replication between LRU servers via https://github.com/t2pellet/distri-lru-server
- TTL for cached items
- Error safe, returns
false
on error forput
,del
,for
andnull
forget