# nncache

> 使用node.js实现的缓存服务器，仿Redis的主要功能

Latest version **1.0.7** (published 2023-11-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install nncache
pnpm add nncache
yarn add nncache
bun add nncache
```

## 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.7 |
| Published | 2023-11-08 |
| First published | 2023-08-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | chenbinfa |
| Maintainers | lanmeng2022 |
| Keywords | Redis |

## Links

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

## Dependencies (2)

- [ws](https://npm.io/package/ws.md) ^8.13.0
- [moment](https://npm.io/package/moment.md) ^2.29.4

## 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.7 (latest) — 2023-11-08
- 1.0.6 — 2023-08-14
- 1.0.5 — 2023-08-14
- 1.0.4 — 2023-08-14
- 1.0.3 — 2023-08-14
- 1.0.2 — 2023-08-14
- 1.0.1 — 2023-08-11
- 1.0.0 — 2023-08-11

## README

# NNCache

使用 node.js 实现的 key-value 缓存服务器，仿 Redis 的主要功能

包括服务端与客户端，能持久化到文件

### 主要接口：

1. set
2. get
3. del
4. sub
5. unsub
6. saveToFile
7. getConnectStatus

### server demo

```javascript
const { createServer } = require("nncache");
createServer({
  port: 90, //监听端口
  autoSaveToFile: true, //是否持久化
  saveToFileInterval: 5000, //自动保存间隙
  debug: true, //输出调试信息
  subEnable: false, //是否开启订阅
  dbFilePath: "./db.json", //数据库文件
});
```

### client demo

```javascript
const { createClient } = require("nncache");

async function main() {
  let cache = createClient({
    url: "ws://localhost:90",
  });
  cache.set("cbf", 123);
  let d = await cache.get("cbf");
  console.log(d);
  setInterval(function () {
    cache.set("cbf2", new Date().valueOf());
  }, 1000);

  let i = 0;
  cache.sub("cbf2", function (json) {
    // i++;
    // if (i == 20) {
    //     cache.unsub('cbf2');
    //   return console.log("取消订阅");
    // }
    console.log("收到订阅：", json);
    // console.log(json);
  });
}

main();
```

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