# cache

URL: /patitas/api/cache/
Section: api
Description: 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

---

> For a complete page index, fetch /patitas/llms.txt.

Open LLM text
(/patitas/api/cache/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fcache%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fcache%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fcache%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fcache%2Findex.txt)

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
```

2Classes2Functions

## Classes

`ParseCache`

2

▼

Protocol for content-addressed parse caches.

Cache key is (content_hash, config_hash). Cached valu…

Bases:

`Protocol`

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 (/patitas/api/nodes/#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 (/patitas/api/nodes/#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 (/patitas/api/nodes/#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 (/patitas/api/nodes/#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 (/patitas/api/config/#ParseConfig)`

ParseConfig to hash

##### Returns

`str`
