route-cache
Advanced tools
Comparing version 0.4.2 to 0.4.3
14
index.js
@@ -27,3 +27,3 @@ 'use strict' | ||
function drainQueue (key) { | ||
debug('drain!', key) | ||
debug('drainQueue:', key) | ||
let subscriber = null | ||
@@ -40,3 +40,3 @@ while (queues[key] && queues[key].length > 0) { | ||
return function (req, res, next) { | ||
var key = req.originalUrl // default cache key | ||
let key = req.originalUrl // default cache key | ||
if (typeof cacheKey === 'function') { | ||
@@ -68,2 +68,3 @@ key = cacheKey(req, res) // dynamic key | ||
res.original_send = res.send | ||
res.original_end = res.end | ||
res.original_json = res.json | ||
@@ -76,3 +77,3 @@ res.original_redirect = res.redirect | ||
var didHandle = false | ||
let didHandle = false | ||
@@ -92,3 +93,3 @@ function rawSend (data, isJson) { | ||
didHandle = true | ||
var body = data instanceof Buffer ? data.toString() : data | ||
const body = data instanceof Buffer ? data.toString() : data | ||
if (res.statusCode < 400) cacheStore.set(key, { body: body, isJson: isJson }, ttl) | ||
@@ -124,2 +125,7 @@ | ||
res.end = (data) => { | ||
res.original_end(data) | ||
drainQueue(key) | ||
} | ||
res.json = function (data) { | ||
@@ -126,0 +132,0 @@ rawSend(data, true) |
{ | ||
"name": "route-cache", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "express middleware for caching your routes", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,3 +10,3 @@ const request = require('supertest') | ||
app.get('/end/1', routeCache.cacheSeconds(4), (req, res) => res.end('res.end 1')) | ||
// app.get('/send/1', routeCache.cacheSeconds(4), (req, res) => res.send('res.send 1')) | ||
app.get('/send/1', routeCache.cacheSeconds(4), (req, res) => res.send('res.send 1')) | ||
@@ -27,19 +27,19 @@ const agent = request.agent(app) | ||
// it('res.end Hit', function (done) { | ||
// agent | ||
// .get('/end/1') | ||
// .expect('res.end 1', done) | ||
// }) | ||
it('res.end Hit', function (done) { | ||
agent | ||
.get('/end/1') | ||
.expect('res.end 1', done) | ||
}) | ||
// it('res.send Miss', function (done) { | ||
// agent | ||
// .get('/send/1') | ||
// .expect('res.send 1', done) | ||
// }) | ||
// | ||
// it('res.send Hit', function (done) { | ||
// agent | ||
// .get('/send/1') | ||
// .expect('res.send 1', done) | ||
// }) | ||
it('res.send Miss', function (done) { | ||
agent | ||
.get('/send/1') | ||
.expect('res.send 1', done) | ||
}) | ||
it('res.send Hit', function (done) { | ||
agent | ||
.get('/send/1') | ||
.expect('res.send 1', done) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
135818
3370
1