cache4js
A simple and easy-to-use cache module with auto recycle for js/nodejs.
How to use ?
1、install
npm install cache4js
2、init
var CACHE_TYPE = TEST_CACHE: RECYCLE_TIME: 1000 * 5 SHOW_LOG: true TEST_CACHE_1: RECYCLE_TIME: 1000 * 10 SHOW_LOG: true;var cache = CACHE_TYPE;
for global use:
globalCACHE_TYPE = TEST_CACHE: RECYCLE_TIME: 1000 * 5 SHOW_LOG: true TEST_CACHE_1: RECYCLE_TIME: 1000 * 10 SHOW_LOG: true;global_Cache = CACHE_TYPE;
3、common use:
cache;cache; var obj = cache;console; //print:abc ;
4、exact time use
var obj = cache;// time in msif obj && obj__time + 5000 > Date // do sth console;
5、for multi-use
var CACHE_TYPE = TEST_CACHE: RECYCLE_TIME: 1000 * 5 SHOW_LOG: true TEST_CACHE_1: RECYCLE_TIME: 1000 * 10 SHOW_LOG: true;var cache1 = CACHE_TYPE;var cache2 = CACHE_TYPE;
cache1 and cache2 are totally seperated.
API
1、config type
var CACHE_TYPE = TEST_CACHE: RECYCLE_TIME: 1000 * 5 SHOW_LOG: true TEST_CACHE_1: RECYCLE_TIME: 1000 * 10 SHOW_LOG: trueVALID_CHECK:false;var cache = CACHE_TYPE;
RECYCLE_TIME: the life time of the special cache obj,count in milliseconds.Default:600000ms;
-------------------------------------------|------------------------------------------------------------------------------------------------------------
SHOW_LOG: it will show the log when the cache obj be recycled only if this config is true;
-------------------------------------------|------------------------------------------------------------------------------------------------------------
VALID_CHECK: it will not recycle anything only if this config is false and has no RECYCLE_TIME config;
-------------------------------------------|------------------------------------------------------------------------------------------------------------
2、interface
; ; ; ; ; ; ;
For more details,please refer to the code.
Contributing
Contributions welcome
License
The original cache4js was distributed under the Apache 2.0 License, and so is this. I've tried to
keep the original copyright and author credits in place, except in sections that I have rewritten
extensively.