eejs: Cache the compiled template, not the template string

r-p-opts
Richard Hansen 2021-01-19 18:43:46 -05:00 committed by John McLear
parent 4d2d439874
commit 517fc88c54
1 changed files with 4 additions and 3 deletions

View File

@ -84,13 +84,14 @@ exports.require = (name, args, mod) => {
args.require = require; args.require = require;
const cache = settings.maxAge !== 0; const cache = settings.maxAge !== 0;
const template = cache && templateCache.get(ejspath) || const template = cache && templateCache.get(ejspath) || ejs.compile(
`<% e._init(__output); %>${fs.readFileSync(ejspath).toString()}<% e._exit(); %>`; `<% e._init(__output); %>${fs.readFileSync(ejspath).toString()}<% e._exit(); %>`,
{filename: ejspath});
if (cache) templateCache.set(ejspath, template); if (cache) templateCache.set(ejspath, template);
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, filename: ejspath}); const res = template(args);
exports.info.file_stack.pop(); exports.info.file_stack.pop();
exports.info.args.pop(); exports.info.args.pop();