Classes
PageDiscoveryCacheEntry
dataclass
Cache entry with metadata and validity information.
PageDiscoveryCacheEntry
dataclass Cache entry with metadata and validity information.
Attributes
| Name | Type | Description |
|---|---|---|
metadata |
PageMetadata |
|
cached_at |
str |
|
is_valid |
bool |
Methods 2
to_dict
to_dict
def to_dict(self) -> dict[str, Any]
Returns
dict[str, Any]
from_dict
staticmethod
from_dict
staticmethod def from_dict(data: dict[str, Any]) -> PageDiscoveryCacheEntry
Parameters 1
data |
dict[str, Any] |
Returns
PageDiscoveryCacheEntry
PageDiscoveryCache
Persistent cache for page metadata enabling lazy page loading.
Purpose:
- Store page metadata (tit…
PageDiscoveryCache
Persistent cache for page metadata enabling lazy page loading.
Purpose:
- Store page metadata (title, date, tags, section, slug)
- Enable incremental discovery (only load changed pages)
- Support lazy loading of full page content on demand
- Validate cache entries to detect stale data
Cache Format (JSON): { "pages": { "content/index.md": { "metadata": { "source_path": "content/index.md", "title": "Home", ... }, "cached_at": "2025-10-16T12:00:00", "is_valid": true } } }
Note: If cache format changes, load will fail and cache rebuilds automatically.
Methods 11
save_to_disk
Save cache to disk.
save_to_disk
def save_to_disk(self) -> None
Save cache to disk.
has_metadata
Check if metadata is cached for a page.
has_metadata
def has_metadata(self, source_path: Path) -> bool
Check if metadata is cached for a page.
Parameters 1
source_path |
Path |
Path to source file |
Returns
True if valid metadata exists in cachebool
—
get_metadata
Get cached metadata for a page.
get_metadata
def get_metadata(self, source_path: Path) -> PageMetadata | None
Get cached metadata for a page.
Parameters 1
source_path |
Path |
Path to source file |
Returns
PageMetadata if found and valid, None otherwisePageMetadata | None
—
add_metadata
Add or update metadata in cache.
add_metadata
def add_metadata(self, metadata: PageMetadata) -> None
Add or update metadata in cache.
Parameters 1
metadata |
PageMetadata |
PageMetadata to cache |
invalidate
Mark a cache entry as invalid.
invalidate
def invalidate(self, source_path: Path) -> None
Mark a cache entry as invalid.
Parameters 1
source_path |
Path |
Path to source file to invalidate |
invalidate_all
Invalidate all cache entries.
invalidate_all
def invalidate_all(self) -> None
Invalidate all cache entries.
clear
Clear all cache entries.
clear
def clear(self) -> None
Clear all cache entries.
get_valid_entries
Get all valid cached metadata entries.
get_valid_entries
def get_valid_entries(self) -> dict[str, PageMetadata]
Get all valid cached metadata entries.
Returns
Dictionary mapping source_path to PageMetadata for valid entriesdict[str, PageMetadata]
—
get_invalid_entries
Get all invalid cached metadata entries.
get_invalid_entries
def get_invalid_entries(self) -> dict[str, PageMetadata]
Get all invalid cached metadata entries.
Returns
Dictionary mapping source_path to PageMetadata for invalid entriesdict[str, PageMetadata]
—
validate_entry
Validate a cache entry against current file hash.
validate_entry
def validate_entry(self, source_path: Path, current_file_hash: str) -> bool
Validate a cache entry against current file hash.
Parameters 2
source_path |
Path |
Path to source file |
current_file_hash |
str |
Current hash of source file |
Returns
True if cache entry is valid (hash matches), False otherwisebool
—
stats
Get cache statistics.
stats
def stats(self) -> dict[str, int]
Get cache statistics.
Returns
Dictionary with cache stats (total, valid, invalid)dict[str, int]
—
Internal Methods 2
__init__
Initialize cache.
__init__
def __init__(self, cache_path: Path | None = None)
Initialize cache.
Parameters 1
cache_path |
Path | None |
Path to cache file (defaults to .bengal/page_metadata.json) |
_load_from_disk
Load cache from disk if it exists.
_load_from_disk
def _load_from_disk(self) -> None
Load cache from disk if it exists.