# node-cache-obj

> a simple cache module using typescript

Latest version **1.0.1** (published 2019-12-18) · ISC license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-12-18 |
| First published | 2019-12-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | hengye |
| Maintainers | hengye |

## Links

- npm: https://www.npmjs.com/package/node-cache-obj
- Repository: https://github.com/HenryYey/ts-obj-cache
- Homepage: https://github.com/HenryYey/koa-ts-logger#readme
- Issues: https://github.com/HenryYey/koa-ts-logger/issues
- npm.io page: https://npm.io/package/node-cache-obj

## Dependencies (1)

- [cross-env](https://npm.io/package/cross-env.md) ^6.0.3

## Recent versions

- 1.0.1 (latest) — 2019-12-18
- 1.0.0 — 2019-12-18

## README

# node-cache-obj

一个缓存模块，可将node后端缓存存入内存， 适用于数据量小、简单的业务场景

## usage
### install
```shell
npm install node-cache-obj 
```
### defind

```js
import { Cache } from "node-cache-obj";

const options = {
  cacheCleanTime: 100000, // 定时清理缓存时间，毫秒
  cacheLimitAmount: 10 // 缓存容量
}

const myCache = new Cache(options);

```

### set && get

```js
const value = JSON.stringify({
  name: "pony",
  age: "18"
});

myCache.setVal({
  key: "a",
  value,
  cacheEffectiveTime: 1800000
})

const result = myCache.getVal("a")
// "{ name: "pony", age: "18" }"
```
### clean Cache 

缓存容量默认为**20**个，缓存有效期默认为**半小时**，默认每隔半小时清除超过阈值的缓存对象。 你可以在defind cache时改变默认配置

```js
// 配置接口
interface ICacheOptions {
  cacheCleanTime?: number; // 定期清理时间
  cacheLimitAmount?: number; // 容量
}
```
### clean Cache by yourself

手动清理过期缓存或所有缓存
```js
// clean noeffective cache
myCache.cleanCache();
// clean all cache
myCache.cleanAllCache();
```

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