Skip to main content

Golem Documentation

Michael Bernstein

golem.staleness

Track file staleness, DAG dependency graphs, and template invalidations for Golem.

Staleness Architecture

Golem maintains an incremental Directed Acyclic Graph (DAG) cache mapping source .adoc

files, included partials (_*.adoc), and layout templates (.pt/.html) to SHA-256 digests. Staleness detection identifies modified documents and traverses reverse dependency links to determine the minimum recompilation set.

Dependency Propagation

Reverse Include Traversal

When an included partial or child document changes, the reverse dependency graph is traversed to invalidate all parent/ancestor documents.

Master Layout Invalidation

Changes to master layout templates (skeleton.pt, page.pt, layout.pt) or global site configuration trigger a full site rebuild.

Granular Component Invalidation

Changes to component templates only invalidate pages containing the matching ASG node types.

class StalenessTracker

PYTHON
class StalenessTracker:

Track document staleness, template digests, and DAG reverse dependency propagation.

Analyzes source file SHA-256 digests against cached records, detects template

modifications, identifies deleted files, and propagates change notifications through the DAG include hierarchy to determine the minimum set of documents requiring recompilation.

config (Any)

Site configuration specifying directories and build settings.

cache (BuildCache)

DAG compilation cache database.

content_dir (Path)

Resolved absolute path to the source content directory.

pm (Any)

Plugin manager instance for stale detection hooks.

plugin_manager (Any)

Alias to pm.

config_path (Path)

Path to site configuration file (golem.toml).

Examples

PYTHON
>>> from pathlib import Path
>>> import tempfile
>>> from golem.cache import BuildCache
>>> from golem.config import GolemConfig
>>> from golem.staleness import StalenessTracker
>>> with tempfile.TemporaryDirectory() as tmp_dir:
...     p = Path(tmp_dir)
...     content = p / "content"
...     content.mkdir()
...     doc = content / "index.adoc"
...     _ = doc.write_text("= Title\nContent")
...     config = GolemConfig(content_dir=str(content), output_dir=str(p / "dist"))
...     cache = BuildCache(p / "cache.json")
...     tracker = StalenessTracker(config, cache, content)
...     outdated = tracker.get_outdated_files()
...     doc.resolve() in outdated
True

Attributes

config

Default value: config

cache

Default value: cache

content_dir

Default value: Path(content_dir).resolve()

pm

Default value: plugin_manager

plugin_manager

Default value: plugin_manager

config_path

Default value: Path(config_path)

init

PYTHON
def __init__(self, config: Any, cache: BuildCache, content_dir: Path, plugin_manager: Any = None, config_path: Path | None = None) -> None:

Initialize the staleness tracker with configuration, cache database, and content path.

config (Any)

Site configuration specifying themes, directories, and build options.

cache (BuildCache)

DAG cache database instance.

content_dir (Path)

Base path to the documentation content directory.

plugin_manager (Any, optional)

Pluggy plugin manager instance. Defaults to None.

config_path (Path | None, optional)

Path to the site configuration file. Defaults to golem.toml.

is_partial

PYTHON
def is_partial(self, path: Path) -> bool:

Check whether a path is designated as a partial within this tracker's content directory.

path (Path)

Filesystem path to evaluate.

bool

True if the path or any parent segment starts with _, False otherwise.

get_reverse_deps

PYTHON
def get_reverse_deps(self, path: Path | str, recursive: bool = True) -> set[Path]:

Retrieve parent documents that include the specified file in the DAG.

Traverses the reverse include dependency graph to identify all parent

documents (and ancestor documents if recursive) that depend on path.

path (Path | str)

Path to the target document or partial dependency.

recursive (bool, optional)

Whether to recursively traverse ancestor parent documents. Defaults to True.

set[Path]

Set of parent document Path objects that depend on path.

get_outdated_files

PYTHON
def get_outdated_files(self, commit: bool = True, adoc_files: list[Path] | None = None) -> set[Path]:

Identify outdated files requiring recompilation through DAG dependency analysis.

Resolves stale documents by:

  1. Scanning .adoc source files and comparing current SHA-256 digests against cached hashes.
  2. Detecting deleted files and removing orphaned cache keys.
  3. Invoking plugin golem_mark_stale hooks for custom invalidation rules.
  4. Propagating direct modifications through reverse include dependencies to mark parent documents as outdated.
  5. Checking global configuration (golem.toml) and template modifications to trigger full or granular invalidations.
commit (bool, optional)

Whether to persist cache modifications (such as deleted file removals and updated template digests) to disk. Defaults to True.

adoc_files (list[Path] | None, optional)

Optional explicit list of .adoc source files to evaluate. If None, scans content_dir. Defaults to None.

set[Path]

Set of absolute Path objects for outdated documents that must be recompiled.

Examples

PYTHON
>>> from pathlib import Path
>>> import tempfile
>>> from golem.cache import BuildCache
>>> from golem.config import GolemConfig
>>> from golem.staleness import StalenessTracker
>>> with tempfile.TemporaryDirectory() as tmp_dir:
...     p = Path(tmp_dir)
...     content = p / "content"
...     content.mkdir()
...     doc = content / "index.adoc"
...     _ = doc.write_text("= Title\nContent")
...     tracker = StalenessTracker(GolemConfig(), BuildCache(p / "cache.json"), content)
...     outdated = tracker.get_outdated_files()
...     doc.resolve() in outdated
True

update_cache_for_file

PYTHON
def update_cache_for_file(self, path: Path, included_files: list[str] | None = None, node_types: list[str] | None = None) -> None:

Update DAG cache entries, SHA-256 hashes, node types, and dependency relations for a document.

Computes the SHA-256 digest of the specified document and updates cache.data["files"] and cache.data["metadata"]. Associates ASG structural node types (such as ["admonition", "listing"]) for granular template invalidation. Resolves included partials and child files (include::...[]) from the supplied included_files list or parses the document AST via asciidoctrine, caching digests for all resolved dependencies, and persists the cache to disk.

path (Path)

Path to the target AsciiDoc document or partial.

included_files (list[str] | None, optional)

Explicit list of resolved dependency file paths. If None, dependencies are parsed from file content. Defaults to None.

node_types (list[str] | None, optional)

List of ASG node type identifiers present in the document. Defaults to None.

None

Cache dictionary is updated in memory and persisted atomically to disk.

Examples

PYTHON
>>> from pathlib import Path
>>> import tempfile
>>> from golem.cache import BuildCache
>>> from golem.config import GolemConfig
>>> from golem.staleness import StalenessTracker
>>> with tempfile.TemporaryDirectory() as tmp_dir:
...     p = Path(tmp_dir)
...     content = p / "content"
...     content.mkdir()
...     doc = content / "index.adoc"
...     _ = doc.write_text("= Title\nContent")
...     tracker = StalenessTracker(GolemConfig(), BuildCache(p / "cache.json"), content)
...     tracker.update_cache_for_file(doc)
...     str(doc.resolve()) in tracker.cache.data["files"]
True

is_partial

PYTHON
def is_partial(path: Path, content_dir: Path) -> bool:

Check whether a file or directory is designated as a partial content unit.

Evaluates whether a path begins with an underscore (_) or resides within any directory segment starting with _ relative to content_dir. Partials are excluded from standalone page generation but tracked as dependencies.

path (Path)

Filesystem path to evaluate.

content_dir (Path)

Base content directory path.

bool

True if the path or any parent segment starts with _, False otherwise.

Examples

PYTHON
>>> from pathlib import Path
>>> from golem.staleness import is_partial
>>> is_partial(Path("content/_partials/header.adoc"), Path("content"))
True
>>> is_partial(Path("content/guide/intro.adoc"), Path("content"))
False