Skip to content

Commit

Permalink
Add html cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed Apr 1, 2020
1 parent b7ac0f7 commit e977102
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/node/eejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var path = require("path");
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks.js");
var resolve = require("resolve");

const templateCache = new Map()

exports.info = {
__output_stack: [],
block_stack: [],
Expand Down Expand Up @@ -114,12 +116,19 @@ exports.require = function (name, args, mod) {

args.e = exports;
args.require = require;
var template = '<% e._init(__output); %>' + fs.readFileSync(ejspath).toString() + '<% e._exit(); %>';


let template
if (!templateCache.has(ejspath)) {
template = '<% e._init(__output); %>' + fs.readFileSync(ejspath).toString() + '<% e._exit(); %>';
templateCache.set(ejspath, template)
} else {
template = templateCache.get(ejspath)
}

exports.info.args.push(args);
exports.info.file_stack.push({path: ejspath, inherit: []});

var res = ejs.render(template, args);
var res = ejs.render(template, args, { cache: true, filename: ejspath });
exports.info.file_stack.pop();
exports.info.args.pop();

Expand Down

0 comments on commit e977102

Please sign in to comment.