# node-smple-cache

> A simple nodejs cache manager

Latest version **0.0.0** (published 2013-11-12) · BSD license · 0 weekly downloads

## Install

```sh
npm install node-smple-cache
pnpm add node-smple-cache
yarn add node-smple-cache
bun add node-smple-cache
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.0.0 |
| Published | 2013-11-12 |
| First published | 2013-11-12 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 113 |
| Author | liguangyi |
| Maintainers | hh54188 |
| Keywords | node.js, cache |

## Links

- npm: https://www.npmjs.com/package/node-smple-cache
- Repository: https://github.com/hh54188/Node-Simple-Cache
- npm.io page: https://npm.io/package/node-smple-cache

## 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

- 0.0.0 (latest) — 2013-11-12

## README

#How to use

##Init

**Cache.createCache([cache algorithm], [cache size])**

- About cache algorithm: you have two choice "LRU" or "LFU", of course you can add your own algorithm. If you not sure which algorithm, you can choose the following manage mode.

```
var cache = require("Cache");
Cache.createCache("LRU", 100 * 100 * 10);
```

##Set

**cache.set(key, value[, expire(millisecond)])**

```
cache.set("key", "value", 1000 * 60);
```

##Get

**cache.get(key)**

```
cache.get("key") // value or null
```

##Clear

**cache.clear()**

##Manage Mode

If you are not sure which cache replacement algorithm is you need, you can try this model, it will caculate the recently 100 * 100 * 3 `get` hit rate in different algorithm.And according the hit rate choose the higher algorithm one:

```
var CacheManage = require("./Manage");
CacheManage.set("key", "value", 1000 * 60);
```

------




前提有两个，首先你的缓存管理程序是用javascript书写的node.js程序

为什么需要自己写缓存管理，

自己写缓存管理的优势在于更快[测试]，

但劣势也很明显，就是无法做到多进程之间的通信

你可能说可以使用socket，不错，因为Redis走的就是socket通信

但这样的代价是会使效率变低

所以说如果你的缓存管理是独享，只存在于一个node.js进程中，那么可以考虑自己构造一个

自己写一个缓存管理工具，有一个问题是 如何控制 缓存使用内存空间的大小

如果在Redis中，你只要进行Config中的maxmemory即可，但是在node.js中，我们没法设定它的运行使用内存大小

我们可以转向另一个东西，数据条数，通过控制数据条数，来间接控制数据大小，虽然不够准确

##大纲


1. Redis与我写的缓存管理 set操作效率，比较，比较平均每条操作要多少时间/每秒能进行多少操作 （即使是在使用pipline的情况下）

2. 我自己的缓存算法需要注意的地方

   - 摒弃数组，使用链表
   - 分离出缓存的索引
   - n与logn 与 delete 操作

3. 实现最基本的LRU算法

4. LRU算法的局限性(LFU算法的优势)

5. 机器学习算法

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