Module

cache

Content-addressed parse cache for Patitas.

Provides (content_hash, config_hash) -> Document caching to avoid re-parsing unchanged content. Enables faster incremental builds (undo/revert, duplicate content) and can replace path-based snapshot caches in consumers like Bengal.

Thread Safety:

DictParseCache is not thread-safe. For parallel parsing, use a cache
implementation with internal locking (e.g. threading.Lock around get/put).

Example:

>>> from patitas import parse, DictParseCache
>>> cache = DictParseCache()
>>> doc1 = parse("# Hello", cache=cache)
>>> doc2 = parse("# Hello", cache=cache)  # Cache hit, no re-parse

Classes

ParseCache 2
Protocol for content-addressed parse caches. Cache key is (content_hash, config_hash). Cached valu…

Protocol for content-addressed parse caches.

Cache key is (content_hash, config_hash). Cached value is Document (AST). Document is immutable, safe to share across threads.

Methods

get 2 Document | None
Return cached Document if present, else None.
def get(self, content_hash: str, config_hash: str) -> Document | None
Parameters
Name Type Description
content_hash
config_hash
Returns
Document | None
put 3
Store Document in cache.
def put(self, content_hash: str, config_hash: str, doc: Document) -> None
Parameters
Name Type Description
content_hash
config_hash
doc
DictParseCache 3
In-memory parse cache using a dict. Not thread-safe. For parallel parsing, wrap with a lock or use…

In-memory parse cache using a dict.

Not thread-safe. For parallel parsing, wrap with a lock or use a thread-safe implementation.

Methods

get 2 Document | None
Return cached Document if present, else None.
def get(self, content_hash: str, config_hash: str) -> Document | None
Parameters
Name Type Description
content_hash
config_hash
Returns
Document | None
put 3
Store Document in cache.
def put(self, content_hash: str, config_hash: str, doc: Document) -> None
Parameters
Name Type Description
content_hash
config_hash
doc
Internal Methods 1
__init__ 0
def __init__(self) -> None

Functions

hash_content 1 str
Compute SHA256 hash of source for cache key.
def hash_content(source: str) -> str
Parameters
Name Type Description
source str

Markdown source text

Returns
str
hash_config 1 str
Compute hash of ParseConfig for cache key. When text_transformer is set, retur…
def hash_config(config: ParseConfig) -> str

Compute hash of ParseConfig for cache key.

When text_transformer is set, returns empty string to disable caching (transformer affects output in non-hashable way).

Parameters
Name Type Description
config ParseConfig

ParseConfig to hash

Returns
str