1.0.4 • Published 8 years ago

smache v1.0.4

Weekly downloads
10
License
MIT
Repository
github
Last release
8 years ago

介绍

smart + cache = smache

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

GitHub: https://github.com/Houfeng/smache

安装

npm install smache --save

用法

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();
1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago