From 93829b9e33623c9877f3ef457346e1e59d1b7303 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 8 Jun 2020 17:21:55 +0100 Subject: [PATCH] pluginfw/performance: Dont cache if max age is 0 (#4098) --- src/node/eejs/index.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/node/eejs/index.js b/src/node/eejs/index.js index bfb445de..057c24c7 100644 --- a/src/node/eejs/index.js +++ b/src/node/eejs/index.js @@ -24,6 +24,7 @@ var fs = require("fs"); var path = require("path"); var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks.js"); var resolve = require("resolve"); +var settings = require('../utils/Settings'); const templateCache = new Map() @@ -118,17 +119,24 @@ exports.require = function (name, args, mod) { args.require = require; 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(); %>'; - templateCache.set(ejspath, template) - } else { - template = templateCache.get(ejspath) } exports.info.args.push(args); exports.info.file_stack.push({path: ejspath, inherit: []}); - - var res = ejs.render(template, args, { cache: true, filename: ejspath }); + if(settings.maxAge !== 0){ + 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.args.pop();