package
Cache req changes and apply them later
npm install memorize-middlewareGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
5.2 kB
Includes dependencies.
Save changes, that middleware did on req and apply them after
var express = require('express');
var app = express();
var memorize = require('memorize-middleware');
var middleware = function (req, res, next) {
console.log('Called once');
req.message = 'Boop!';
next();
};
app.use(memorize(middleware));
app.get('/', function (req, res, next) {
res.send(req.message);
});
app.listen(8080);There are couple states in which memorize works:
updateInterval set - it will be scheduled.If updateInterval is set:
Creates middleware, that will call middleware and cache changes, that it did to req object.
Type: Function
Middleware, which changes should be cached.
Type: Number
Default: 0 — never
How often (in milliseconds) should memorize request new data for middleware. Don't make it too low.
The MIT License (MIT) © Vsevolod Strukchinsky