Classes
CachedSource
dataclass
Metadata about a cached source.
CachedSource
dataclass Metadata about a cached source.
Attributes
| Name | Type | Description |
|---|---|---|
source_key |
str |
|
cached_at |
datetime |
|
entry_count |
int |
|
checksum |
str | None |
ContentLayerManager
Manages content from multiple sources.
Handles:
- Source registration (local, remote, custom)
- Pa…
ContentLayerManager
Manages content from multiple sources.
Handles:
- Source registration (local, remote, custom)
- Parallel async fetching
- Disk caching with TTL and invalidation
- Aggregation of all sources into unified content list
Methods 6
register_source
Register a content source.
register_source
def register_source(self, name: str, source_type: str, config: dict[str, Any]) -> None
Register a content source.
Parameters 3
name |
str |
Unique name for this source instance |
source_type |
str |
Type identifier ('local', 'github', 'rest', 'notion') |
config |
dict[str, Any] |
Source-specific configuration |
register_custom_source
Register a custom source instance.
register_custom_source
def register_custom_source(self, name: str, source: ContentSource) -> None
Register a custom source instance.
Parameters 2
name |
str |
Unique name for this source |
source |
ContentSource |
ContentSource implementation instance |
fetch_all
async
Fetch content from all registered sources.
Fetches from all sources in paralle…
fetch_all
async async def fetch_all(self, use_cache: bool = True) -> list[ContentEntry]
Fetch content from all registered sources.
Fetches from all sources in parallel, using cache when available and falling back to cached content in offline mode.
Parameters 1
use_cache |
bool |
Whether to use cached content if available |
Returns
List of all content entries from all sourceslist[ContentEntry]
—
clear_cache
Clear cached content.
clear_cache
def clear_cache(self, source_name: str | None = None) -> int
Clear cached content.
Parameters 1
source_name |
str | None |
Specific source to clear, or None for all |
Returns
Number of cache files deletedint
—
get_cache_status
Get status of all cached sources.
get_cache_status
def get_cache_status(self) -> dict[str, dict[str, Any]]
Get status of all cached sources.
Returns
Dictionary mapping source names to cache statusdict[str, dict[str, Any]]
—
fetch_all_sync
Synchronous wrapper for fetch_all().
fetch_all_sync
def fetch_all_sync(self, use_cache: bool = True) -> list[ContentEntry]
Synchronous wrapper for fetch_all().
Parameters 1
use_cache |
bool |
Whether to use cached content if available |
Returns
List of all content entrieslist[ContentEntry]
—
Internal Methods 6
__init__
Initialize content layer manager.
__init__
def __init__(self, cache_dir: Path | None = None, cache_ttl: timedelta = timedelta(hours=1), offline: bool = False) -> None
Initialize content layer manager.
Parameters 3
cache_dir |
Path | None |
Directory for caching remote content (default: .bengal/content_cache) |
cache_ttl |
timedelta |
Time-to-live for cached content (default: 1 hour) |
offline |
bool |
If True, only use cached content (no network requests) |
_fetch_source
async
Fetch content from a single source with caching.
_fetch_source
async async def _fetch_source(self, name: str, source: ContentSource, use_cache: bool) -> list[ContentEntry]
Fetch content from a single source with caching.
Parameters 3
name |
str |
Source name |
source |
ContentSource |
Source instance |
use_cache |
bool |
Whether to check cache first |
Returns
List of content entries from this sourcelist[ContentEntry]
—
_is_cache_valid
Check if cached content is still valid.
_is_cache_valid
def _is_cache_valid(self, name: str, expected_key: str) -> bool
Check if cached content is still valid.
Parameters 2
name |
str |
Source name |
expected_key |
str |
Expected cache key (based on current config) |
Returns
True if cache is valid and can be usedbool
—
_load_cache
Load cached entries from disk.
_load_cache
def _load_cache(self, name: str) -> list[ContentEntry] | None
Load cached entries from disk.
Parameters 1
name |
str |
Source name |
Returns
List of cached entries, or None if cache unavailablelist[ContentEntry] | None
—
_save_cache
Save entries to cache.
_save_cache
def _save_cache(self, name: str, entries: list[ContentEntry], cache_key: str) -> None
Save entries to cache.
Parameters 3
name |
str |
Source name |
entries |
list[ContentEntry] |
Entries to cache |
cache_key |
str |
Cache key for validation |
__repr__
__repr__
def __repr__(self) -> str
Returns
str