Module

rendering.plugins.directives.cache

Directive content caching for performance optimization.

Caches parsed directive content by content hash to avoid expensive re-parsing of identical directive blocks.

Classes

DirectiveCache
LRU cache for parsed directive content. Uses content hash to detect changes and reuse parsed AST. …
10

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.
2 Any | None
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

Any | None

Cached parsed result or None if not found

put
Cache parsed content.
3 None
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.
0 None
def clear(self) -> None

Clear the cache.

enable
Enable caching.
0 None
def enable(self) -> None

Enable caching.

disable
Disable caching.
0 None
def disable(self) -> None

Disable caching.

stats
Get cache statistics.
0 dict[str, Any]
def stats(self) -> dict[str, Any]

Get cache statistics.

Returns

dict[str, Any]

Dictionary with cache statistics:

  • hits: Number of cache hits
  • misses: Number of cache misses
  • hit_rate: Cache hit rate (0.0 to 1.0)
  • size: Current cache size
  • max_size: Maximum cache size
  • enabled: Whether caching is enabled

reset_stats
Reset hit/miss statistics without clearing cache.
0 None
def reset_stats(self) -> None

Reset hit/miss statistics without clearing cache.

Internal Methods 3
__init__
Initialize directive cache.
1 None
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…
2 str
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

str

Cache key string

__repr__
String representation.
0 str
def __repr__(self) -> str

String representation.

Returns

str

Functions

get_cache
Get the global directive cache instance.
0 DirectiveCache
def get_cache() -> DirectiveCache

Get the global directive cache instance.

Returns

DirectiveCache

Global DirectiveCache instance

configure_cache
Configure the global directive cache.
2 None
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.
0 None
def clear_cache() -> None

Clear the global directive cache.

get_cache_stats
Get statistics from the global directive cache.
0 dict[str, Any]
def get_cache_stats() -> dict[str, Any]

Get statistics from the global directive cache.

Returns

dict[str, Any]

Cache statistics dictionary