From 517fc88c5450370b425f7e6f25f408e270be0bbd Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 19 Jan 2021 18:43:46 -0500 Subject: [PATCH] eejs: Cache the compiled template, not the template string --- src/node/eejs/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/node/eejs/index.js b/src/node/eejs/index.js index 61f5eb0dd..9f04fe1fb 100644 --- a/src/node/eejs/index.js +++ b/src/node/eejs/index.js @@ -84,13 +84,14 @@ exports.require = (name, args, mod) => { args.require = require; const cache = settings.maxAge !== 0; - const template = cache && templateCache.get(ejspath) || - `<% e._init(__output); %>${fs.readFileSync(ejspath).toString()}<% e._exit(); %>`; + const template = cache && templateCache.get(ejspath) || ejs.compile( + `<% e._init(__output); %>${fs.readFileSync(ejspath).toString()}<% e._exit(); %>`, + {filename: ejspath}); if (cache) templateCache.set(ejspath, template); exports.info.args.push(args); exports.info.file_stack.push({path: ejspath}); - const res = ejs.render(template, args, {cache, filename: ejspath}); + const res = template(args); exports.info.file_stack.pop(); exports.info.args.pop();