express-lru
Advanced tools
Comparing version 0.1.0 to 1.0.0
@@ -6,3 +6,4 @@ var AsyncCache = require('async-cache'); | ||
var ttl = options.ttl || 30000; | ||
var loader = new AsyncCache({max: 1000, maxAge: ttl, load: noop}); | ||
var max = options.max || 1000; | ||
var loader = new AsyncCache({max: max, maxAge: ttl, load: noop}); | ||
var hasher = options.hasher || function(req) { | ||
@@ -24,2 +25,3 @@ return req.originalUrl; | ||
} | ||
// we skip caching by returning an "error" to async-cache) | ||
var nocache = res.statusCode && res.statusCode !== 200; | ||
@@ -26,0 +28,0 @@ callback(nocache, { |
{ | ||
"name": "express-lru", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"description": "Varnish-like cache middleware for Express", | ||
@@ -22,3 +22,3 @@ "main": "index.js", | ||
"author": "Brian Reavis <brian@naturalatlas.com>", | ||
"license": "Apache License, v2.0", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
@@ -25,0 +25,0 @@ "url": "https://github.com/naturalatlas/express-lru/issues" |
@@ -17,3 +17,9 @@ # express-lru | ||
var expresslru = require('express-lru'); | ||
var cache = expresslru({ttl: 60000, skip: function(req) { return !!req.user; }}); | ||
var cache = expresslru({ | ||
max: 1000, | ||
ttl: 60000, | ||
skip: function(req) { | ||
return !!req.user; | ||
} | ||
}); | ||
@@ -27,3 +33,3 @@ app.get('/myroute', cache, function(req, res, next) { | ||
Copyright © 2015 [Natural Atlas, Inc.](https://github.com/naturalatlas) & [Contributors](https://github.com/naturalatlas/express-lru/graphs/contributors) | ||
Copyright © 2015–2016 [Natural Atlas, Inc.](https://github.com/naturalatlas) & [Contributors](https://github.com/naturalatlas/express-lru/graphs/contributors) | ||
@@ -30,0 +36,0 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0 |
@@ -7,5 +7,6 @@ var async = require('async'); | ||
function runsequence(expectSkip, route, options, test, done) { | ||
var app = express(); | ||
var agent = request.agent(app); | ||
var app = express(); | ||
var agent = request.agent(app); | ||
function runsequence(routePattern, expectSkip, route, options, test, done) { | ||
options.ttl = 50; | ||
@@ -15,3 +16,3 @@ | ||
var executions = 0; | ||
app.get('/route', lru(options), function(req, res, next) { | ||
app.get(routePattern, lru(options), function(req, res, next) { | ||
executions++; | ||
@@ -24,3 +25,3 @@ route(req, res, next); | ||
setTimeout(function() { | ||
var _agent = agent.get('/route'); | ||
var _agent = agent.get(routePattern); | ||
test(_agent); | ||
@@ -52,3 +53,3 @@ _agent.end(function(err) { | ||
}; | ||
runsequence(false, route, {}, function(agent) { | ||
runsequence('/route1', false, route, {}, function(agent) { | ||
agent | ||
@@ -66,3 +67,3 @@ .expect('Content-Type', /application\/json/) | ||
}; | ||
runsequence(false, route, {}, function(agent) { | ||
runsequence('/route2', false, route, {}, function(agent) { | ||
agent | ||
@@ -76,3 +77,3 @@ .expect('Content-Type', /text\/test/) | ||
var route = function(req, res, next) { res.set({'Content-Type': 'text/test'}).send(new Buffer('hello')); }; | ||
runsequence(false, route, {}, function(agent) { | ||
runsequence('/route3', false, route, {}, function(agent) { | ||
agent | ||
@@ -86,3 +87,3 @@ .expect('Content-Type', /text\/test/) | ||
var route = function(req, res, next) { res.set({'Content-Type': 'text/test'}).send({a:'b'}); }; | ||
runsequence(false, route, {}, function(agent) { | ||
runsequence('/route4', false, route, {}, function(agent) { | ||
agent | ||
@@ -100,3 +101,3 @@ .expect('Content-Type', /text\/test/) | ||
}; | ||
runsequence(true, route, {}, function(agent) { | ||
runsequence('/route5', true, route, {}, function(agent) { | ||
agent | ||
@@ -114,3 +115,3 @@ .expect('Content-Type', /text\/plain/) | ||
var skip = function(req) { return true; }; | ||
runsequence(true, route, {skip: skip}, function(agent) { | ||
runsequence('/route6', true, route, {skip: skip}, function(agent) { | ||
agent | ||
@@ -117,0 +118,0 @@ .expect('Content-Type', /text\/test/) |
Sorry, the diff of this file is not supported yet
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
19724
0
144
0
37