1.0.1 • Published 2 years ago

lowcache v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

简单的内存数据缓存

用途

带有缓存时间的简单的NodeJS存储, 支持set/get/del

定义如下:

/**
 * 带有时间有效期的简单缓存机制
 * @param {Number} timeLength 缓存有效期,以秒为单位; 当timeLenth为0时表示永久有效;默认为0;
 * @param {Number} autoClearTime 缓存检查周期,以秒为单位; timeLenth为0时无效; 默认值为timeLength的10倍;
 */
function LowCache(timeLength, autoClearTime){
}

用法举例

const LowCache = require('lowcache');
let cache = new LowCache(10, 20); //缓存周期10s, 自动清理周期20s;
cache.set('a','1111');
cache.set('b','2222');

console.log(cache.get('a'));
setTimeout(function(){
	console.log('after 9s: ',cache.get('a'));
}, 9000);
setTimeout(function(){
	console.log('after 12s: ',cache.get('a'));
}, 12000);
setTimeout(function(){
	console.log('after 22s: ',cache.get('b'));
}, 22000);
1.0.1

2 years ago

1.0.0

2 years ago