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

torres-express-cache

v1.0.6

Published

Simple callback flow for managing cache on expressjs

Downloads

6

Readme

torres-express-cache

Simple callback flow for managing cache. Just set a function for setting cache and a function after reading cache.

Install

$ npm install torres-express-cache

Usage

var cache = require('torres-express-cache');
var cachetime = 10000; //10s

cache.getCache( "key" , cachetime ,
	//when no cache
	function(next){ 
		//here your requests

		//pass your data to next and it is cached
		next(data);
	},
	//next
	function(data){		
		//get cache or passed info
	}
);
getCache(key,cachetime, nocache, next)
  • key is a unique key for each cache element.
  • cachetime is the time in ms for cache.
  • nocache is the function which is executed if no cache is found. Here is where you retrive the data, get cached it and passed to next function.
  • next is callback executed after getting cache (if exists) or after making requests and caching data.

You can store cache manually by calling method

putCache(key,data)

Example


app.get('index', function(req,res) {
   
	cache.getCache("index", 1000 * 3600,
		//when no cache
		function(next){ 	
			//request to api
			blog.getIndexPosts(function(posts){ 
				//save files in cache, then next.
				next( {posts: posts} );
			});
		},
		//next
		function(posts){		
			res.info = posts;
			res.render(req,res);
		});
	}

});


Config

Default config is:

cache.config({
	enabled: true,
	verbose: true
});

Enabled

If not enabled just pass data to callback function without caching it. It is very usefull in Express if you want to dissable cache in development mode. Just enable cache only when NODE_ENV is production like this:

cache.config({
	enabled: app.get('env') == production ,
	verbose: true
});

Verbose

If verbose is enabled it logs when cache is set or retrieved.