pluginfw/performance: Dont cache if max age is 0 (#4098)
parent
3e78b79d9d
commit
93829b9e33
|
@ -24,6 +24,7 @@ var fs = require("fs");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks.js");
|
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks.js");
|
||||||
var resolve = require("resolve");
|
var resolve = require("resolve");
|
||||||
|
var settings = require('../utils/Settings');
|
||||||
|
|
||||||
const templateCache = new Map()
|
const templateCache = new Map()
|
||||||
|
|
||||||
|
@ -118,17 +119,24 @@ exports.require = function (name, args, mod) {
|
||||||
args.require = require;
|
args.require = require;
|
||||||
|
|
||||||
let template
|
let template
|
||||||
if (!templateCache.has(ejspath)) {
|
if (settings.maxAge !== 0){ // don't cache if maxAge is 0
|
||||||
|
if (!templateCache.has(ejspath)) {
|
||||||
|
template = '<% e._init(__output); %>' + fs.readFileSync(ejspath).toString() + '<% e._exit(); %>';
|
||||||
|
templateCache.set(ejspath, template)
|
||||||
|
} else {
|
||||||
|
template = templateCache.get(ejspath)
|
||||||
|
}
|
||||||
|
}else{
|
||||||
template = '<% e._init(__output); %>' + fs.readFileSync(ejspath).toString() + '<% e._exit(); %>';
|
template = '<% e._init(__output); %>' + fs.readFileSync(ejspath).toString() + '<% e._exit(); %>';
|
||||||
templateCache.set(ejspath, template)
|
|
||||||
} else {
|
|
||||||
template = templateCache.get(ejspath)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.info.args.push(args);
|
exports.info.args.push(args);
|
||||||
exports.info.file_stack.push({path: ejspath, inherit: []});
|
exports.info.file_stack.push({path: ejspath, inherit: []});
|
||||||
|
if(settings.maxAge !== 0){
|
||||||
var res = ejs.render(template, args, { cache: true, filename: ejspath });
|
var res = ejs.render(template, args, { cache: true, filename: ejspath });
|
||||||
|
}else{
|
||||||
|
var res = ejs.render(template, args, { cache: false, filename: ejspath });
|
||||||
|
}
|
||||||
exports.info.file_stack.pop();
|
exports.info.file_stack.pop();
|
||||||
exports.info.args.pop();
|
exports.info.args.pop();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue