Skip to content
This repository has been archived by the owner on Jun 25, 2019. It is now read-only.

jillro/cache-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cache-cache

A cache middleware for express application serving static or almost static content. It generates a Last-Modified header based on last application restart.

If a valid If-Modified-Since header is sent by the client, it will send a 304 Not Modified response with empty body, and not even hit express routes.

With just express server, it allows browser caching.

With reverse proxies such as Nginx or Varnish, it will use it to cache every request hitting the middleware until your process restart. Each express route will be hit only once by process restart. It works also with multi-process server behind reverse proxy.

Usage

const cache = require('cache-cache');

var app = express();

// static files
app.use('/static/', express.static(__dirname + '/static/', {maxAge: '60000'}));

// cache-cache can be used globally
app.use(cache());

// or with any given routes
app.use('/blog', cache());

// other middlewares and routes
app.use(othermiddleware());
app.get(function(req, res) {
    res.send('ok');
});

About

A very simple HTTP cache module for application serving static content.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published