# cached_blocks

URL: /kida/api/template/cached_blocks/
Section: template
Description: Cached blocks dict wrapper for block cache optimization.

---

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

Open LLM text
(/kida/api/template/cached_blocks/index.txt)

Share with AI

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

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

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

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

Module

#
`template.cached_blocks`

Cached blocks dict wrapper for block cache optimization.

1Class

## Classes

`CachedBlocksDict`

11

▼

Dict wrapper that returns cached HTML for site-scoped blocks.

Used by Kida's block cache optimizat…

Dict wrapper that returns cached HTML for site-scoped blocks.

Used by Kida's block cache optimization to intercept .get() calls
from templates and return pre-rendered HTML for site-wide blocks
(nav, footer, etc.).

Complexity: O(1) for lookups.

#### Methods

`get`

2

`BlockCallable | Any`

▼

Intercept .get() calls to return cached HTML when available.

`def get(self, key: str, default: Any = None) -> BlockCallable | Any`

##### Parameters

Name
Type
Description

`key`
`—`

`default`
`—`

Default:`None`

##### Returns

`BlockCallable | Any`

`setdefault`

2

`BlockCallable | Any`

▼

Preserve setdefault() behavior for block registration.

Kida templates use .set…

`def setdefault(self, key: str, default: Any = None) -> BlockCallable | Any`

Preserve setdefault() behavior for block registration.

Kida templates use .setdefault() to register their own block functions
if not already overridden by a child template.

##### Parameters

Name
Type
Description

`key`
`—`

`default`
`—`

Default:`None`

##### Returns

`BlockCallable | Any`

`keys`

0

`set[str]`

▼

Support .keys() iteration.

`def keys(self) -> set[str]`

##### Returns

`set[str]`

`copy`

0

`dict[str, Any]`

▼

Support .copy() for embed/include operations.

`def copy(self) -> dict[str, Any]`

##### Returns

`dict[str, Any]`

Internal Methods
7

▼

`__init__`

4

▼

`def __init__(self, original: dict[str, Any] | None, cached: dict[str, str], cached_names: frozenset[str] | set[str], stats: dict[str, int] | None = None)`

##### Parameters

Name
Type
Description

`original`
`—`

`cached`
`—`

`cached_names`
`—`

`stats`
`—`

Default:`None`

`_make_wrapper`

1

`BlockCallable`

▼

Create a block-signature wrapper returning cached HTML.

staticmethod

`def _make_wrapper(html: str) -> BlockCallable`

##### Parameters

Name
Type
Description

`html`
`—`

##### Returns

`BlockCallable`

`_record_hit`

0

▼

Record cache hit (thread-safe when stats shared).

`def _record_hit(self) -> None`

`_record_miss`

0

▼

Record cache miss (thread-safe when stats shared).

`def _record_miss(self) -> None`

`__getitem__`

1

`BlockCallable | Any`

▼

Support dict[key] access.

`def __getitem__(self, key: str) -> BlockCallable | Any`

##### Parameters

Name
Type
Description

`key`
`—`

##### Returns

`BlockCallable | Any`

`__setitem__`

2

▼

Support dict[key] = value assignment.

`def __setitem__(self, key: str, value: Any) -> None`

##### Parameters

Name
Type
Description

`key`
`—`

`value`
`—`

`__contains__`

1

`bool`

▼

Support 'key in dict' checks.

`def __contains__(self, key: str) -> bool`

##### Parameters

Name
Type
Description

`key`
`—`

##### Returns

`bool`
