0.3.1 • Published 11 years ago

http-cache v0.3.1

Weekly downloads
4
License
-
Repository
github
Last release
11 years ago

http-cache

Build Status NPM version Dependency Status

Install

npm install http-cache

https://npmjs.org/package/http-cache

What is it?

Getting Started with Connect/Express

Using Connect or Express?

var
	connect = require("connect"),
	http = require("http"),
	HttpCache = require("http-cache")
;

var app = connect()
	.use(new HttpCache({ }))
	.use(function(req, res) {
		res.end("Cache this response! Time=" + new Date().getTime());
	});

http.createServer(app).listen(8392);

Getting Started with HTTP

Real coders use no middleware? We've got you covered...

var
	http = require("http"),
	HttpCache = require("http-cache")
;

var httpcache = new HttpCache({ });
http.createServer(function(req, res) {
	httpcache(req, res, function() {
		res.end("Cache this response! Time=" + new Date().getTime());
	});
}).listen(8392);

Custom Rules

Both synchronous and asynchronous rules may be provided:

httpcache({
	rules: function(req, res) {
		// do not cache users folder
		return (/\/users\//i.test(req.url) === false);
	}
});

Async rules leverage cb instead of returning...

httpcache({
	rules: function(req, res, cb) {
		setTimeout(function() {
			// do not cache users folder
			cb(null, /\/users\//i.test(req.url) === false);
		}, 100);
	}
});

Multiple rules may be provided as well... (will be processed in parallel)

httpcache({
	rules: [ rule1, rule2, rule3 ]
});

Tests & Code Coverage

npm test

Now you can view coverage using any browser here:

coverage/lcov-report/index.html

License

MIT

TODO

  • TTL Support
  • Purge Support
0.3.1

11 years ago

0.3.0

11 years ago

0.2.2

11 years ago

0.2.0

11 years ago

0.1.6

11 years ago

0.1.5

11 years ago

0.1.4

11 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago