# smache

> Smart caching module

Latest version **1.0.4** (published 2016-09-29) · MIT license · 0 weekly downloads

## Install

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

## 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.4 |
| Published | 2016-09-29 |
| First published | 2016-07-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Houfeng |
| Maintainers | houzhanfeng |
| Keywords | cache, memory-cache, memory |

## Links

- npm: https://www.npmjs.com/package/smache
- Repository: https://github.com/Houfeng/smache
- Homepage: https://github.com/Houfeng/smache#readme
- Issues: https://github.com/Houfeng/smache/issues
- npm.io page: https://npm.io/package/smache

## 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.4 (latest) — 2016-09-29
- 1.0.3 — 2016-09-28
- 1.0.2 — 2016-09-28
- 1.0.1 — 2016-07-06
- 1.0.0 — 2016-07-06

## README

# 介绍 

[sm]art + c[ache] = smache   

Smache 是一个方便的内存缓存模块，可以通过一些简单缓存策略避免无限占用更多的内存，同时确保最常用最应该被缓存的对象被缓存。

GitHub: [https://github.com/Houfeng/smache](https://github.com/Houfeng/smache)

<!--more-->

# 安装  
```sh
npm install smache --save
```

# 用法

```js
const Cache = require('smache');

//创建实例
var cache = new Cache({
  //最多缓存的对象数量，省略时表示不做数量限制
  //在达到最大数量时，会移除「最久没用到的」的缓存项
  max: 1000, 
  //最长缓存生命周期，单位毫秒，省略时表示永久
  //到期时自动移除
  ttl: 1000 * 60 
});

//添加
cache.set(key,value);
cache.set(key,value,ttl); //可以单设定某项的 ttl

//获取
var value = cache.get(key);

//移除
cache.remove(key);

//清空
cache.clear();

```

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