npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cache4js

v1.0.2

Published

A simple and easy-to-use cache module with auto recycle for js/nodejs.

Readme

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 = require('cache4js')(CACHE_TYPE);

for global use:

global.CACHE_TYPE = {
    TEST_CACHE: {RECYCLE_TIME: 1000 * 5, SHOW_LOG: true},
    TEST_CACHE_1: {RECYCLE_TIME: 1000 * 10, SHOW_LOG: true}
};
global._Cache = require('cache4js')(CACHE_TYPE);

3、common use:

cache.add(CACHE_TYPE.TEST_CACHE, 1, {value:'abc'});
cache.add(CACHE_TYPE.TEST_CACHE_1, 1, {value:'abc'});

var obj = cache.get(CACHE_TYPE.TEST_CACHE, 1);
console.log(obj.value); //print:abc

setTimeout(function () {
    var obj = cache.get(CACHE_TYPE.TEST_CACHE, 1);
    console.log(obj && obj.value || 'null'); //print:null,already recycled in 5s
}, 6000);

4、exact time use

var obj = cache.get(CACHE_TYPE.TEST_CACHE, 1);
// time in ms
if (obj && obj.__time + 5000 > Date.now()) {
    // do sth
    console.log(obj.value);
}

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 = require('cache4js')(CACHE_TYPE);
var cache2 = require('cache4js')(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: true,VALID_CHECK:false}
};
var cache = require('cache4js')(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

add(type,key,obj);   
get(type,key);   
del(type,key);   
addType(type);   
getType(type);   
delType(type);   
clearType(type);   

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.