From 4d2d439874eec7e81179ccc61c6d4d6372f3533e Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 19 Jan 2021 17:57:19 -0500 Subject: [PATCH] eejs: Simplify cache lookup logic --- src/node/eejs/index.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/node/eejs/index.js b/src/node/eejs/index.js index 428a67637..61f5eb0dd 100644 --- a/src/node/eejs/index.js +++ b/src/node/eejs/index.js @@ -83,21 +83,14 @@ exports.require = (name, args, mod) => { args.e = exports; args.require = require; - let template; - 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(); %>`; - } + const cache = settings.maxAge !== 0; + const template = cache && templateCache.get(ejspath) || + `<% e._init(__output); %>${fs.readFileSync(ejspath).toString()}<% e._exit(); %>`; + 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: settings.maxAge !== 0, filename: ejspath}); + const res = ejs.render(template, args, {cache, filename: ejspath}); exports.info.file_stack.pop(); exports.info.args.pop();