eejs: Simplify cache lookup logic

r-p-opts
Richard Hansen 2021-01-19 17:57:19 -05:00 committed by John McLear
parent c8c3929058
commit 4d2d439874
1 changed files with 5 additions and 12 deletions

View File

@ -83,21 +83,14 @@ exports.require = (name, args, mod) => {
args.e = exports; args.e = exports;
args.require = require; args.require = require;
let template; const cache = settings.maxAge !== 0;
if (settings.maxAge !== 0) { // don't cache if maxAge is 0 const template = cache && templateCache.get(ejspath) ||
if (!templateCache.has(ejspath)) { `<% e._init(__output); %>${fs.readFileSync(ejspath).toString()}<% e._exit(); %>`;
template = `<% e._init(__output); %>${fs.readFileSync(ejspath).toString()}<% e._exit(); %>`; if (cache) templateCache.set(ejspath, template);
templateCache.set(ejspath, template);
} else {
template = templateCache.get(ejspath);
}
} else {
template = `<% e._init(__output); %>${fs.readFileSync(ejspath).toString()}<% e._exit(); %>`;
}
exports.info.args.push(args); exports.info.args.push(args);
exports.info.file_stack.push({path: ejspath}); 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.file_stack.pop();
exports.info.args.pop(); exports.info.args.pop();