# cluster-lru-cache

> Cache service realization in clustered systems

Latest version **1.0.5** (published 2021-10-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install cluster-lru-cache
pnpm add cluster-lru-cache
yarn add cluster-lru-cache
bun add cluster-lru-cache
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2021-10-09 |
| First published | 2021-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 34.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Konstantin Tsepelev |
| Maintainers | datapain |
| Keywords | cluster, lru, cache |

## Links

- npm: https://www.npmjs.com/package/cluster-lru-cache
- Repository: https://github.com/datapain/cluster-lru-cache
- Homepage: https://github.com/datapain/cluster-lru-cache#readme
- Issues: https://github.com/datapain/cluster-lru-cache
- npm.io page: https://npm.io/package/cluster-lru-cache

## Dependencies (4)

- [nanoid](https://npm.io/package/nanoid.md) ^3.1.22
- [lru-cache](https://npm.io/package/lru-cache.md) ^6.0.0
- [ts-results](https://npm.io/package/ts-results.md) ~3.2.1
- [object-hash](https://npm.io/package/object-hash.md) ^2.1.1

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2021-10-09
- 1.0.4 — 2021-10-09
- 1.0.2 — 2021-04-20
- 1.0.1 — 2021-04-20
- 1.0.0 — 2021-04-18
- 0.2.6 — 2021-04-18
- 0.2.5 — 2021-04-18
- 0.2.4 — 2021-04-16
- 0.2.3 — 2021-04-16
- 0.2.2 — 2021-04-16
- 0.2.1 — 2021-04-16
- 0.2.0 — 2021-04-15
- 0.1.6 — 2021-04-14
- 0.1.5 — 2021-04-12
- 0.1.4 — 2021-04-12
- … 7 more at https://npm.io/package/cluster-lru-cache/versions

## README

# Inmemory Nodejs Cluster LRU Cache

It's LRU based cache provider for the clustered and non-clustered systems.
We are dependent on the lru-cache package and provide flexible API to use in different cases.

This solution based on Node.JS IPC requests from the main thread to worker threads and its communications.

Everything is like everyone else, but it is simple to use, just look:

```
import cluster from 'cluster';
import { LruCache } from 'cluster-lru-cache';
import { cpus } from 'os';

const maxForks = cpus().length;

const LRU = (enabled: boolean) => new LruCache({
  enabled,
  max: 1000,
  maxAge: 86400 * 1000,
  updateOnGet: true,
});

const enabled = true;

if(cluster.isMaster) {
  for (let i = 0; i < maxForks; i++) {
    cluster.fork();
  }
  LRU(enabled);
} else {
  const cache = LRU(enabled);

  /**
    cache.hash({foo:'bar'});
    cache.get({foo:'bar'});
    cache.has({foo:'bar'});
    cache.set({foo:'bar'},{'bar':'foo'});
    cache.getByHash('somelonghashstring');
    cache.hasByHash('somelonghashstring');
    cache.setByHash('somelonghashstring',{'bar':'foo'});
    cache.setStatus(false) // cache disable
    cache.setStatus(true) // cache enable
    cache.reset();
  */
}

```


Also, we use the `ts-results` to our methods, which means:
* process chaining
* rxjs compatible operators
* no extra throw errors
* fptible
* easy to understand
* transparent flow
* etc

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