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 🙏

© 2024 – Pkg Stats / Ryan Hefner

rcache

v0.2.0

Published

rcache is a node cache module for cache your data. Using rcache you can set, get, delete the data in your cache, and custom the auto refresh function to reload the data.

Downloads

35

Readme

rcache

Build Status

rcache is a node cache module for cache your data. Using rcache, you can set, get, delete the data in your cache, and even custom the auto refresh function to reload the data.

All the functions for handle your cache data will include two ways, sync and async version. So there will be like getSync or getAsync function.

Getting started

npm install rcache --save

Usage

Init your cache object

var cache = require('rcache');

This init way will using the default settings.All the settings will be list here:

'ttl': 0, //ttl is the default cache live time, value is 0 means we will never delete it.(ttl unit is millisecond)

'errorOrNull': false, //throw a error or return a null when delete or get a not exist key,default false means will return a null value

'autoRefresh': true, // autoRefresh means your key has the ability to refresh itself. default true means turn on this function.

'refreshInterval': 10000, //only availible when the autoRefresh is setting to true.

You can custom it using cache.init() function

var cache = require('rcache');
cache.init({'ttl':10000});

Set new key-value.

var cache = require('rcache');
cache.setSync('hello','world');
cache.setAsync('hello1','world1',function(err){
    if(!err){
        console.log('setting success');
    }
});

If the cache already has the key you want to set, just replace it and refresh its ttl. There also no limit about size of the cache data, maybe later will add some limitations.

Get the key-value.

var cache = require('rcache');
var val = cache.getSync('hello');
cache.getAsync('hello',function(err,val){
    if(!err){
        console.log('get value success');
    }
});

If the key not in the cache ,the getSync will return null or throw a error based your option: errorOrNull.

Delete the key-value.

var cache = require('rcache');
var ifSuccess = cache.deleteSync('hello');
cache.deleteAsync('hello',function(err){
    if(!err){
        console.log('delete key success');
    }
});

If the key not in the cache ,the deleteSync will return null or throw a error based your option: errorOrNull.

Flush all cached data.

var cache = require('rcache');
var ifSuccess = cache.flushAllSync();
cache.flushAllSync('hello',function(err){
    if(!err){
        console.log('flushAll keys success');
    }
});

Set auto refresh

Auto refresh function will auto update the value in your cache based its callback function.

var cache = require('rcache');
cache.setSync('user',[{"name":"mike"},{"name":"alice"}]);
setAutoRefresh('user',function(cb){
     User.find({},function(err,docs){
         cb(docs);
     });
},10000);

Other functions

  • keys(): get the list of the keys in your cache
  • keysNumber(): get the number of the cached keys.
  • getStat(): get the stat of the cache.
  • isExistKey():check if the key in your cache.