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.0.3 to 0.1.0

42

index.js

@@ -7,20 +7,52 @@ var Eidetic = require('eidetic');

var queues = {};
module.exports.cacheSeconds = function(ttl) {
return function(req, res, next) {
var self = this;
var cache = cachestore.get(req.path);
//var send = res.send;
res.original_send = res.send;
// returns the value immediately
if (cache) {
res.send(cache);
} else {
var send = res.send;
res.send = function(string) {
return;
}
if (!queues[req.path]) {
queues[req.path] = [];
}
// first request will get rendered output
if (queues[req.path].length === 0
&& queues[req.path].push(function noop(){})) {
res.send = function (string) {
var body = string instanceof Buffer ? string.toString() : string;
cachestore.put(req.url, body, ttl);
send.call(this, body);
// drain the queue so anyone else waiting for
// this value will get their responses.
var subscriber = null;
while (subscriber = queues[req.path].shift()) {
if (subscriber) {
process.nextTick(subscriber);
}
}
res.original_send(body);
};
next();
// subsequent requests will batch while the first computes
} else {
queues[req.path].push(function() {
var body = cachestore.get(req.path);
res.send(body);
});
}
}
};

2

package.json
{
"name": "route-cache",
"version": "0.0.3",
"version": "0.1.0",
"description": "express middleware for caching your routes",

@@ -5,0 +5,0 @@ "main": "index.js",

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