Classes
AssetReference
dataclass
Reference to an asset from a page.
AssetReference
dataclass Reference to an asset from a page.
Attributes
| Name | Type | Description |
|---|---|---|
url |
str |
|
type |
str |
|
source_page |
str |
AssetDependencyEntry
dataclass
Cache entry for asset dependencies.
Implements the Cacheable protocol for type-safe serialization.
AssetDependencyEntry
dataclass Cache entry for asset dependencies.
Implements the Cacheable protocol for type-safe serialization.
CacheableAttributes
| Name | Type | Description |
|---|---|---|
assets |
set[str] |
|
tracked_at |
str |
|
is_valid |
bool |
Methods 4
to_cache_dict
Serialize to cache-friendly dictionary (Cacheable protocol).
to_cache_dict
def to_cache_dict(self) -> dict[str, Any]
Serialize to cache-friendly dictionary (Cacheable protocol).
Returns
dict[str, Any]
from_cache_dict
classmethod
Deserialize from cache dictionary (Cacheable protocol).
from_cache_dict
classmethod def from_cache_dict(cls, data: dict[str, Any]) -> AssetDependencyEntry
Deserialize from cache dictionary (Cacheable protocol).
Parameters 1
data |
dict[str, Any] |
Returns
AssetDependencyEntry
to_dict
Alias for to_cache_dict (test compatibility).
to_dict
def to_dict(self) -> dict[str, Any]
Alias for to_cache_dict (test compatibility).
Returns
dict[str, Any]
from_dict
classmethod
Alias for from_cache_dict (test compatibility).
from_dict
classmethod def from_dict(cls, data: dict[str, Any]) -> AssetDependencyEntry
Alias for from_cache_dict (test compatibility).
Parameters 1
data |
dict[str, Any] |
Returns
AssetDependencyEntry
AssetDependencyMap
Persistent map of page-to-asset dependencies for incremental discovery.
Purpose:
- Track which ass…
AssetDependencyMap
Persistent map of page-to-asset dependencies for incremental discovery.
Purpose:
- Track which assets each page references
- Enable on-demand asset discovery
- Skip asset discovery for unchanged pages
- Support incremental asset fingerprinting
Cache Format (JSON): { "version": 1, "pages": { "content/index.md": { "assets": [ "/images/logo.png", "/css/style.css", "/fonts/inter.woff2" ], "tracked_at": "2025-10-16T12:00:00", "is_valid": true } } }
Methods 13
save_to_disk
Save asset dependencies to disk.
save_to_disk
def save_to_disk(self) -> None
Save asset dependencies to disk.
track_page_assets
Track assets referenced by a page.
track_page_assets
def track_page_assets(self, source_path: Path, assets: set[str]) -> None
Track assets referenced by a page.
Parameters 2
source_path |
Path |
Path to source page |
assets |
set[str] |
Set of asset URLs/paths referenced by the page |
get_page_assets
Get assets referenced by a page.
get_page_assets
def get_page_assets(self, source_path: Path) -> set[str] | None
Get assets referenced by a page.
Parameters 1
source_path |
Path |
Path to source page |
Returns
Set of asset URLs if found and valid, None otherwiseset[str] | None
—
has_assets
Check if page has tracked assets.
has_assets
def has_assets(self, source_path: Path) -> bool
Check if page has tracked assets.
Parameters 1
source_path |
Path |
Path to source page |
Returns
True if page has valid asset trackingbool
—
get_all_assets
Get all unique assets referenced by any page.
get_all_assets
def get_all_assets(self) -> set[str]
Get all unique assets referenced by any page.
Returns
Set of all asset URLs across all pagesset[str]
—
get_assets_for_pages
Get all assets referenced by a set of pages.
get_assets_for_pages
def get_assets_for_pages(self, source_paths: list[Path]) -> set[str]
Get all assets referenced by a set of pages.
Parameters 1
source_paths |
list[Path] |
List of page paths to find assets for |
Returns
Set of all asset URLs referenced by the given pagesset[str]
—
invalidate
Mark a page's asset tracking as invalid.
invalidate
def invalidate(self, source_path: Path) -> None
Mark a page's asset tracking as invalid.
Parameters 1
source_path |
Path |
Path to source page |
invalidate_all
Invalidate all asset tracking entries.
invalidate_all
def invalidate_all(self) -> None
Invalidate all asset tracking entries.
clear
Clear all asset tracking.
clear
def clear(self) -> None
Clear all asset tracking.
get_valid_entries
Get all valid asset tracking entries.
get_valid_entries
def get_valid_entries(self) -> dict[str, set[str]]
Get all valid asset tracking entries.
Returns
Dictionary mapping source_path to asset set for valid entriesdict[str, set[str]]
—
get_invalid_entries
Get all invalid asset tracking entries.
get_invalid_entries
def get_invalid_entries(self) -> dict[str, set[str]]
Get all invalid asset tracking entries.
Returns
Dictionary mapping source_path to asset set for invalid entriesdict[str, set[str]]
—
stats
Get asset dependency map statistics.
stats
def stats(self) -> dict[str, Any]
Get asset dependency map statistics.
Returns
Dictionary with cache statsdict[str, Any]
—
get_asset_pages
Get all pages that reference a specific asset.
get_asset_pages
def get_asset_pages(self, asset_url: str) -> set[str]
Get all pages that reference a specific asset.
Parameters 1
asset_url |
str |
Asset URL to find references for |
Returns
Set of page paths that reference this assetset[str]
—
Internal Methods 2
__init__
Initialize asset dependency map.
__init__
def __init__(self, cache_path: Path | None = None)
Initialize asset dependency map.
Parameters 1
cache_path |
Path | None |
Path to cache file (defaults to .bengal/asset_deps.json) |
_load_from_disk
Load asset dependencies from disk if file exists.
_load_from_disk
def _load_from_disk(self) -> None
Load asset dependencies from disk if file exists.