Skip to content

Commit

Permalink
Require key for cacheable custom template extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jan 8, 2022
1 parent ef494a9 commit fca0104
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/TemplateContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,20 @@ class TemplateContent {
str,
bypassMarkdown
);
if (cacheable && cache.has(key)) {
return cache.get(key);
if (cacheable && key) {
if (cache.has(key)) {
return cache.get(key);
}

// Compilation is async, so we eagerly cache a Promise that eventually
// resolves to the compiled function
cache.set(
key,
new Promise((resolve) => {
res = resolve;
})
);
}

// Compilation is async, so we eagerly cache a Promise that eventually
// resolves to the compiled function
cache.set(
key,
new Promise((resolve) => {
res = resolve;
})
);
}

let templateBenchmark = bench.get("Template Compile");
Expand All @@ -299,7 +301,7 @@ class TemplateContent {
return fn;
} catch (e) {
let [cacheable, key, cache] = this._getCompileCache(str, bypassMarkdown);
if (cacheable) {
if (cacheable && key) {
cache.delete(key);
}
debug(`Having trouble compiling template ${this.inputPath}: %O`, str);
Expand Down

0 comments on commit fca0104

Please sign in to comment.