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.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();