cache.key

Page actions AI-ready formats and sharing
Open LLM text
Share with AI
Ask Claude Ask ChatGPT Ask Gemini Ask Copilot

Cache key derivation — Vary-header-aware, pluggable key functions.

Cache key derivation — Vary-header-aware, pluggable key functions.

cache.key

Name Type Default Description
type
qualified_name
element_type
description
source_file
line_number
is_autodoc
autodoc_element
_autodoc_template
_autodoc_url_path
_autodoc_page_type
title
doc_content_hash

Symbols on this page

default_cache_key
function
def default_cache_key(request: Request) -> str

Derive a cache key from the request.

Includes URL query and htmx response shape so full-page, fragment, boosted, and history-restore responses cannot masquerade as each other.

Format:chirp:{method}:{path}:{hash(inputs)}

Parameters

Name Type Default Description
request Request
vary_aware_cache_key
function
def vary_aware_cache_key(request: Request, vary_headers: tuple[str, ...] = ()) -> str

Cache key that includes Vary header values for differentiation.

Parameters

Name Type Default Description
request Request
vary_headers tuple[str, ...] ()
query_cache_key
function async
async def query_cache_key(request: Request, vary_headers: tuple[str, ...] = ()) -> str

Return an opaque, body-aware cache key for one QUERY request.

This function only designs the key;CacheMiddlewarecontinues to bypass QUERY until its separate explicit opt-in lands. It reads the body throughbody(), so the existing request limit is enforced and the exact bytes remain cached for the handler. Call it before any direct iteration ofrequest.stream().

Every selected-representation input is length-framed into SHA-256. Raw body, URI, and header values never appear in the returned key. Content metadata is intentionally exact: semantic media-type normalization remains a separate, media-specific opt-in.

Requests carrying Cookie or Authorization are ineligible rather than keyed; this preserves CacheMiddleware's private-request bypass boundary.

Parameters

Name Type Default Description
request Request
vary_headers tuple[str, ...] ()
_hash_field
function
def _hash_field(digest: Any, label: bytes, value: bytes) -> None

Hash one unambiguous label/value frame without copying request content.

Parameters

Name Type Default Description
digest Any
label bytes
value bytes

View source · /home/runner/work/chirp/chirp/site/../src/chirp/cache/key.py:1