Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

route-cache

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

route-cache - npm Package Compare versions

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)
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc