# distri-lru

> Library for geo-distributed LRU cache

Latest version **0.1.5** (published 2023-11-09) · AGPL-3.0-only license · 0 weekly downloads

## Install

```sh
npm install distri-lru
pnpm add distri-lru
yarn add distri-lru
bun add distri-lru
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2023-11-09 |
| First published | 2023-11-08 |
| Weekly downloads | 0 |
| License | AGPL-3.0-only |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | 16.x |
| Dependencies | 4 |
| Unpacked size | 706.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Tenzin Pelletier |
| Maintainers | t2pellet |

## Links

- npm: https://www.npmjs.com/package/distri-lru
- npm.io page: https://npm.io/package/distri-lru

## Dependencies (4)

- [public-ip](https://npm.io/package/public-ip.md) ^6.0.1
- [axios-retry](https://npm.io/package/axios-retry.md) ^3.8.1
- [@turf/helpers](https://npm.io/package/@turf/helpers.md) ^6.5.0
- [@turf/nearest-point](https://npm.io/package/@turf/nearest-point.md) ^6.5.0

## Recent versions

- 0.1.5 (latest) — 2023-11-09
- 0.1.4 — 2023-11-08
- 0.1.2 — 2023-11-08
- 0.1.1 — 2023-11-08
- 0.1.0 — 2023-11-08

## README

# distri-lru

A library for geo-distributed LRU cache with real-time replication

## Requirements

Need to have cache servers setup as according to:
<br />
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
1. `put(key: string, val: object, options: { ip?: string, ttl?: number }): Promise<boolean>`
2. `get(key: string, options: { ip?: string }): Promise<object | undefined | null>`
3. `del(key: string, options: { ip?: string }): Promise<boolean>`
4. `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 for `put`, `del`, `for` and `null` for `get`

---
_Source: https://npm.io/package/distri-lru · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
