Classes
DirectiveCache
LRU cache for parsed directive content.
Uses content hash to detect changes and reuse parsed AST.
…
DirectiveCache
LRU cache for parsed directive content.
Uses content hash to detect changes and reuse parsed AST. Implements LRU eviction to limit memory usage.
Expected impact: 30-50% speedup on pages with repeated directive patterns.
Methods 7
get
Get cached parsed content.
get
def get(self, directive_type: str, content: str) -> Any | None
Get cached parsed content.
Parameters 2
directive_type |
str |
Type of directive |
content |
str |
Directive content |
Returns
Cached parsed result or None if not foundAny | None
—
put
Cache parsed content.
put
def put(self, directive_type: str, content: str, parsed: Any) -> None
Cache parsed content.
Parameters 3
directive_type |
str |
Type of directive |
content |
str |
Directive content |
parsed |
Any |
Parsed result to cache |
clear
Clear the cache.
clear
def clear(self) -> None
Clear the cache.
enable
Enable caching.
enable
def enable(self) -> None
Enable caching.
disable
Disable caching.
disable
def disable(self) -> None
Disable caching.
stats
Get cache statistics.
stats
def stats(self) -> dict[str, Any]
Get cache statistics.
Returns
Dictionary with cache statistics:dict[str, Any]
—
reset_stats
Reset hit/miss statistics without clearing cache.
reset_stats
def reset_stats(self) -> None
Reset hit/miss statistics without clearing cache.
Internal Methods 3
__init__
Initialize directive cache.
__init__
def __init__(self, max_size: int = 1000)
Initialize directive cache.
Parameters 1
max_size |
int |
Maximum number of cached items (default 1000) |
_make_key
Generate cache key from directive type and content.
Uses SHA256 hash for deter…
_make_key
def _make_key(self, directive_type: str, content: str) -> str
Generate cache key from directive type and content.
Uses SHA256 hash for deterministic, collision-resistant keys.
Parameters 2
directive_type |
str |
Type of directive (tabs, note, etc.) |
content |
str |
Directive content |
Returns
Cache key stringstr
—
__repr__
String representation.
__repr__
def __repr__(self) -> str
String representation.
Returns
str
Functions
get_cache
Get the global directive cache instance.
get_cache
def get_cache() -> DirectiveCache
Get the global directive cache instance.
Returns
Global DirectiveCache instanceDirectiveCache
—
configure_cache
Configure the global directive cache.
configure_cache
def configure_cache(max_size: int | None = None, enabled: bool | None = None) -> None
Configure the global directive cache.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
max_size |
int | None |
None |
Maximum cache size (None to keep current) |
enabled |
bool | None |
None |
Whether to enable caching (None to keep current) |
clear_cache
Clear the global directive cache.
clear_cache
def clear_cache() -> None
Clear the global directive cache.
get_cache_stats
Get statistics from the global directive cache.
get_cache_stats
def get_cache_stats() -> dict[str, Any]
Get statistics from the global directive cache.
Returns
Cache statistics dictionarydict[str, Any]
—