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.2.5 to 0.2.6

44

index.js

@@ -0,1 +1,2 @@

'use strict';
var Eidetic = require('eidetic');

@@ -38,29 +39,32 @@ var cacheStore = new Eidetic({

// first request will get rendered output
if (queues[key].length === 0 && queues[key].push(function noop(){})) {
var didHandle = false;
var didHandle = false;
function rawSend(data, isJson) {
didHandle = true;
var key = req.originalUrl;
function rawSend(data, isJson) {
didHandle = true;
var body = data instanceof Buffer ? data.toString() : data;
if (res.statusCode < 400) cacheStore.put(key, { body: body, isJson: isJson }, ttl);
var body = data instanceof Buffer ? data.toString() : data;
if (res.statusCode < 400) cacheStore.put(key, { body: body, isJson: isJson }, ttl);
// drain the queue so anyone else waiting for
// this value will get their responses.
var subscriber = null;
while (subscriber === queues[key].shift()) {
if (subscriber) {
process.nextTick(subscriber);
}
// drain the queue so anyone else waiting for
// this value will get their responses.
var subscriber = null;
while (subscriber === queues[key].shift()) {
if (subscriber) {
process.nextTick(subscriber);
}
}
if (isJson) {
res.original_json(body);
} else {
res.original_send(body);
}
if (isJson) {
res.original_json(body);
} else {
res.original_send(body);
}
}
// first request will get rendered output
if (queues[key].length === 0 && queues[key].push(function noop(){})) {
didHandle = false;
res.send = function (data) {

@@ -67,0 +71,0 @@ if (didHandle) {

{
"name": "route-cache",
"version": "0.2.5",
"version": "0.2.6",
"description": "express middleware for caching your routes",

@@ -27,3 +27,2 @@ "main": "index.js",

"mocha": "2.5.3",
"should": "9.0.2",
"supertest": "1.2.0"

@@ -30,0 +29,0 @@ },

@@ -8,3 +8,3 @@ # Route-Cache

[![NPM](https://nodei.co/npm/route-cache.png?downloads=true&downloadRank=true)](https://nodei.co/npm/route-cache/) [![NPM](https://nodei.co/npm-dl/route-cache.png?months=6&height=3)](https://nodei.co/npm/route-cache/)
[![NPM](https://nodei.co/npm/route-cache.png?downloads=true&downloadRank=true)](https://nodei.co/npm/route-cache/)

@@ -11,0 +11,0 @@ Make your routes do this ->![dodging](http://forgifs.com/gallery/d/80400-8/Muhammad-Ali-dodges-punches.gif)

@@ -0,3 +1,3 @@

'use strict';
var request = require('supertest'),
should = require('should'),
routeCache = require('../index'),

@@ -17,2 +17,10 @@ express = require('express');

app.get('/hello/1', routeCache.cacheSeconds(1), function (req, res) {
res.send('Hello/1');
});
app.get('/hello/:num([0-9])', routeCache.cacheSeconds(1), function (req, res) {
res.send('Hello param:' + req.params.num);
});
app.get('/500', routeCache.cacheSeconds(10), function (req, res) {

@@ -57,2 +65,14 @@ res.status(500).send('Internal server error: ' + Math.random());

it('1st Hello w/ param', function (done) {
agent
.get('/hello/1')
.expect('Hello/1', done);
});
it('2nd Hello w/ param', function (done) {
agent
.get('/hello/2')
.expect('Hello param:2', done);
});
it('1st Redirect to hello', function (done) {

@@ -59,0 +79,0 @@ agent

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