Module

core.site.page_caches

Page caching mixin for Site.

Provides cached page list properties (regular_pages, generated_pages, listable_pages) with automatic invalidation when pages change.

Related Modules:

  • bengal.core.site.core: Main Site dataclass using this mixin
  • bengal.core.page: Page model

Classes

PageCachesMixin
Mixin providing cached page list properties. Requires these attributes on the host class: - pa…
6

Mixin providing cached page list properties.

Requires these attributes on the host class:

  • pages: list[Page]
  • _regular_pages_cache: list[Page] | None
  • _generated_pages_cache: list[Page] | None
  • _listable_pages_cache: list[Page] | None
  • _page_path_map: dict[str, Page] | None
  • _page_path_map_version: int

Attributes

Name Type Description
pages list[Page]
_regular_pages_cache list[Page] | None
_generated_pages_cache list[Page] | None
_listable_pages_cache list[Page] | None
_page_path_map dict[str, Page] | None
_page_path_map_version int

Methods 6

regular_pages property
Get only regular content pages (excludes generated taxonomy/archive pages). PE…
list[Page]
def regular_pages(self) -> list[Page]

Get only regular content pages (excludes generated taxonomy/archive pages).

PERFORMANCE: This property is cached after first access for O(1) subsequent lookups. The cache is automatically invalidated when pages are modified.

Returns

list[Page]

List of regular Page objects (excludes tag pages, archive pages, etc.)

generated_pages property
Get only generated pages (taxonomy, archive, pagination pages). PERFORMANCE: T…
list[Page]
def generated_pages(self) -> list[Page]

Get only generated pages (taxonomy, archive, pagination pages).

PERFORMANCE: This property is cached after first access for O(1) subsequent lookups. The cache is automatically invalidated when pages are modified.

Returns

list[Page]

List of generated Page objects (tag pages, archive pages, pagination, etc.)

listable_pages property
Get pages that should appear in listings (excludes hidden pages). This propert…
list[Page]
def listable_pages(self) -> list[Page]

Get pages that should appear in listings (excludes hidden pages).

This property respects the visibility system:

  • Excludes pages withhidden: true
  • Excludes pages withvisibility.listings: false
  • Excludes draft pages

Use this for:

  • "Recent posts" sections
  • Archive pages
  • Category/tag listings
  • Any public-facing page list

Usesite.pageswhen you need ALL pages including hidden ones (e.g., for sitemap generation where you filter separately).

PERFORMANCE: This property is cached after first access for O(1) subsequent lookups. The cache is automatically invalidated when pages are modified.

Returns

list[Page]

List of Page objects that should appear in public listings

get_page_path_map
Get cached page path lookup map for O(1) page resolution. Cache is automatical…
0 dict[str, Page]
def get_page_path_map(self) -> dict[str, Page]

Get cached page path lookup map for O(1) page resolution.

Cache is automatically invalidated when page count changes, covering add/remove operations in dev server.

Returns

dict[str, Page]

Dictionary mapping source_path strings to Page objects

invalidate_page_caches
Invalidate cached page lists when pages are modified. Call this after: - Addin…
0 None
def invalidate_page_caches(self) -> None

Invalidate cached page lists when pages are modified.

Call this after:

  • Adding/removing pages
  • Modifying page metadata (especially _generated flag or visibility)
  • Any operation that changes the pages list

This ensures cached properties (regular_pages, generated_pages, listable_pages, page_path_map) will recompute on next access.

invalidate_regular_pages_cache
Invalidate the regular_pages cache. Call this after modifying the pages list o…
0 None
def invalidate_regular_pages_cache(self) -> None

Invalidate the regular_pages cache.

Call this after modifying the pages list or page metadata that affects the _generated flag. More specific than invalidate_page_caches() if you only need to invalidate regular_pages.