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!';
};
app.use(memorize(middleware));
app.get('/', function (req, res, next) {
res.send(req.message);
});
app.listen(8080);
Creates middleware, that will call middleware
and cache changes, that it did to req object.
Type: Function
Middleware, which changes should be cached.
Type: Boolean
Default: false
If enabled, middleware will be executed on startup, instead of be executed on first request.
Type: Number
Default: 0
โ never
How often (in milliseconds) should memorize
request new data for middleware. Don't make it too low.
Type: Boolean
Default: false
Should client be notified (next
callback called) when error is occured, while updating cache.
Otherwise errors will be ignored and memorize
will try to update cache again.
The MIT License (MIT) ยฉ Vsevolod Strukchinsky