Module

cache.build_cache.rendered_output_cache

Rendered output caching mixin for BuildCache.

Provides methods for caching fully rendered HTML output to skip both markdown parsing AND template rendering. Optimization #3 from the cache RFC.

Key Concepts:

  • Caches final HTML (post-template, ready to write)
  • Validates against content, metadata, template, and dependencies
  • Expected 20-40% faster incremental builds

Related Modules:

  • bengal.cache.build_cache.core: Main BuildCache class
  • bengal.rendering.renderer: Page rendering
  • plan/active/rfc-orchestrator-performance.md: Performance RFC

Classes

RenderedOutputCacheMixin
Mixin providing rendered output caching (Optimization #3). Requires these attributes on the host c…
5

Mixin providing rendered output caching (Optimization #3).

Requires these attributes on the host class:

  • rendered_output: dict[str, dict[str, Any]]
  • is_changed: Callable[[Path], bool] (from FileTrackingMixin)

Attributes

Name Type Description
rendered_output dict[str, dict[str, Any]]

Methods 5

is_changed
Check if file changed (provided by FileTrackingMixin).
1 bool
def is_changed(self, file_path: Path) -> bool

Check if file changed (provided by FileTrackingMixin).

Parameters 1
file_path Path
Returns

bool

store_rendered_output
Store fully rendered HTML output in cache. This allows skipping BOTH markdown …
5 None
def store_rendered_output(self, file_path: Path, html: str, template: str, metadata: dict[str, Any], dependencies: list[str] | None = None) -> None

Store fully rendered HTML output in cache.

This allows skipping BOTH markdown parsing AND template rendering for pages where content, template, and metadata are unchanged. Expected to provide 20-40% faster incremental builds.

Parameters 5
file_path Path

Path to source file

html str

Fully rendered HTML (post-template, ready to write)

template str

Template name used for rendering

metadata dict[str, Any]

Page metadata (frontmatter)

dependencies list[str] | None

List of template/partial paths this page depends on

get_rendered_output
Get cached rendered HTML if still valid. Validates that: 1. Content file hasn'…
3 str | None
def get_rendered_output(self, file_path: Path, template: str, metadata: dict[str, Any]) -> str | None

Get cached rendered HTML if still valid.

Validates that:

  1. Content file hasn't changed (via file_fingerprints)
  2. Metadata hasn't changed (via metadata_hash)
  3. Template name matches
  4. Template files haven't changed (via dependencies)
  5. Config hasn't changed (caller should validate config_hash)
Parameters 3
file_path Path

Path to source file

template str

Current template name

metadata dict[str, Any]

Current page metadata

Returns

str | None

Cached HTML string if valid, None if invalid or not found

invalidate_rendered_output
Remove cached rendered output for a file.
1 None
def invalidate_rendered_output(self, file_path: Path) -> None

Remove cached rendered output for a file.

Parameters 1
file_path Path

Path to file

get_rendered_output_stats
Get rendered output cache statistics.
0 dict[str, Any]
def get_rendered_output_stats(self) -> dict[str, Any]

Get rendered output cache statistics.

Returns

dict[str, Any]

Dictionary with cache stats