1.0.0 • Published 7 years ago

express-rc v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

Express.js caching middleware

Install

yarn install express-rc

Usage

'use strict';

const express = require('express');
const redis = require('redis');
const cache = require('cache');

const app = express();

app.use(cache({
	ttl: 60 // How long (in seconds) to hold onto cached responses
	enabled: true, // Enable caching (setting exists to easily disable in specific environments)
	includeBody: true, // Include the body in hashing the request
	disabled: [ // Specify some routes that shouldn't be cached
		'/ping',
		'/auth'
	],
	headers: [ // Any unique headers you want to include when hashing the request
		'X-Access-Token'
	],
	client: redis.createClient() // A node redis client
}));

app.use('/', (req, res) => {
	res.ttl(5) // Optionally override the global ttl in middleware
	return next();
});

What Express response methods are cached?

  • .set()
  • .send()
  • .json()
  • .status()