Module

cache.build_cache.taxonomy_index_mixin

Taxonomy indexing mixin for BuildCache.

Provides methods for maintaining bidirectional tag/page indexes for fast taxonomy reconstruction during incremental builds.

Key Concepts:

  • Forward index: page_path → set[tag_slug]
  • Inverted index: tag_slug → set[page_path]
  • O(1) taxonomy reconstruction from cache
  • Efficient tag change detection

Related Modules:

  • bengal.cache.build_cache.core: Main BuildCache class
  • bengal.orchestration.taxonomy: Taxonomy orchestration
  • bengal.cache.taxonomy_index: TaxonomyIndex utilities

Classes

TaxonomyIndexMixin
Mixin providing taxonomy indexing for fast incremental builds. Requires these attributes on the ho…
6

Mixin providing taxonomy indexing for fast incremental builds.

Requires these attributes on the host class:

  • taxonomy_deps: dict[str, set[str]]
  • page_tags: dict[str, set[str]]
  • tag_to_pages: dict[str, set[str]]
  • known_tags: set[str]

Attributes

Name Type Description
taxonomy_deps dict[str, set[str]]
page_tags dict[str, set[str]]
tag_to_pages dict[str, set[str]]
known_tags set[str]

Methods 6

add_taxonomy_dependency
Record that a taxonomy term affects a page.
2 None
def add_taxonomy_dependency(self, taxonomy_term: str, page: Path) -> None

Record that a taxonomy term affects a page.

Parameters 2
taxonomy_term str

Taxonomy term (e.g., "tag:python")

page Path

Page that uses this taxonomy term

get_previous_tags
Get tags from previous build for a page.
1 set[str]
def get_previous_tags(self, page_path: Path) -> set[str]

Get tags from previous build for a page.

Parameters 1
page_path Path

Path to page

Returns

set[str]

Set of tags from previous build (empty set if new page)

update_tags
Store current tags for a page (for next build's comparison).
2 None
def update_tags(self, page_path: Path, tags: set[str]) -> None

Store current tags for a page (for next build's comparison).

Parameters 2
page_path Path

Path to page

tags set[str]

Current set of tags for the page

update_page_tags
Update tag index when a page's tags change. Maintains bidirectional index: - p…
2 set[str]
def update_page_tags(self, page_path: Path, tags: set[str]) -> set[str]

Update tag index when a page's tags change.

Maintains bidirectional index:

  • page_tags: path → tags (forward)
  • tag_to_pages: tag → paths (inverted)

This is the key method that enables O(1) taxonomy reconstruction.

Parameters 2
page_path Path

Path to page source file

tags set[str]

Current set of tags for this page (original case, e.g., "Python", "Web Dev")

Returns

set[str]

Set of affected tag slugs (tags added, removed, or modified)

get_pages_for_tag
Get all page paths for a given tag.
1 set[str]
def get_pages_for_tag(self, tag_slug: str) -> set[str]

Get all page paths for a given tag.

Parameters 1
tag_slug str

Tag slug (e.g., 'python', 'web-dev')

Returns

set[str]

Set of page path strings

get_all_tags
Get all known tag slugs from previous build.
0 set[str]
def get_all_tags(self) -> set[str]

Get all known tag slugs from previous build.

Returns

set[str]

Set of tag slugs