diff --git a/src/Template.js b/src/Template.js index c0a9568a9..18678bdd0 100755 --- a/src/Template.js +++ b/src/Template.js @@ -115,6 +115,8 @@ class Template extends TemplateContent { if (types.data) { delete this._dataCache; + // delete this._usePermalinkRoot; + // delete this._stats; } if (types.render) { @@ -264,6 +266,7 @@ class Template extends TemplateContent { } async usePermalinkRoot() { + // @cachedproperty if (this._usePermalinkRoot === undefined) { // TODO this only works with immediate front matter and not data files let { data } = await this.getFrontMatterData(); @@ -394,8 +397,10 @@ class Template extends TemplateContent { async getData() { if (!this._dataCache) { + // @cachedproperty this._dataCache = this.#getData(); } + return this._dataCache; } @@ -441,6 +446,7 @@ class Template extends TemplateContent { // This is the primary render mechanism, called via TemplateMap->populateContentDataInMap async renderPageEntryWithoutLayout(pageEntry) { + // @cachedproperty if (!this._cacheRenderedPromise) { this._cacheRenderedPromise = this.renderDirect(pageEntry.rawInput, pageEntry.data); this.renderCount++; @@ -858,7 +864,7 @@ class Template extends TemplateContent { } async renderPageEntry(pageEntry) { - // cache with transforms output + // @cachedproperty if (!pageEntry.template._cacheRenderedTransformsAndLayoutsPromise) { pageEntry.template._cacheRenderedTransformsAndLayoutsPromise = this.#renderPageEntryWithLayoutsAndTransforms(pageEntry); @@ -964,6 +970,7 @@ class Template extends TemplateContent { } async getInputFileStat() { + // @cachedproperty if (this._stats) { return this._stats; } diff --git a/src/TemplateContent.js b/src/TemplateContent.js index 05f6d8fed..143d95828 100644 --- a/src/TemplateContent.js +++ b/src/TemplateContent.js @@ -73,7 +73,6 @@ class TemplateContent { if (types.read) { delete this.readingPromise; delete this.inputContent; - delete this.frontMatter; delete this._frontMatterDataCache; } } @@ -235,10 +234,11 @@ class TemplateContent { async read() { if (!this.readingPromise) { if (!this.inputContent) { - // cache the promise + // @cachedproperty this.inputContent = this.getInputContent(); } + // @cachedproperty this.readingPromise = this.#read(); } @@ -355,6 +355,7 @@ class TemplateContent { async getFrontMatterData() { if (!this._frontMatterDataCache) { + // @cachedproperty this._frontMatterDataCache = this.#getFrontMatterData(); } diff --git a/src/TemplateWriter.js b/src/TemplateWriter.js index 46b4421fb..c747ad042 100755 --- a/src/TemplateWriter.js +++ b/src/TemplateWriter.js @@ -182,6 +182,7 @@ class TemplateWriter { }; } + // incrementalFileShape is `template` or `copy` (for passthrough file copy) async _addToTemplateMapIncrementalBuild(incrementalFileShape, paths, to = "fs") { // Render overrides are only used when `--ignore-initial` is in play and an initial build is not run let ignoreInitialBuild = !this.isRunInitialBuild; @@ -197,6 +198,11 @@ class TemplateWriter { templates.push(tmpl); + // This must happen before data is generated for the incremental file only + if (incrementalFileShape === "template" && tmpl.inputPath === this.incrementalFile) { + tmpl.resetCaches(); + } + // IMPORTANT: This is where the data is first generated for the template promises.push(this.templateMap.add(tmpl)); } @@ -254,8 +260,7 @@ class TemplateWriter { // Order of templates does not matter here, they’re reordered later based on dependencies in TemplateMap.js for (let tmpl of templates) { if (incrementalFileShape === "template" && tmpl.inputPath === this.incrementalFile) { - tmpl.resetCaches(); - + // Cache is reset above (to invalidate data cache at the right time) tmpl.setDryRunViaIncremental(false); } else if (!tmpl.isRenderableDisabled() && !tmpl.isRenderableOptional()) { // Related to the template but not the template (reset the render cache, not the read cache)