Problem
A custom key_builder that adds a dimension (user ID, tenant, locale) has to rebuild the whole default key by hand. The per-user example in HTTP_CACHING.md did that and repeated #230: it joined the raw Host header and path with |||. Every hand-rolled builder is one forgotten escape_key_component away from the same key-poisoning bug.
Proposal
Add a public helper that builds the default key and appends extra components, encoding every component:
from fastapi_cachex import build_cache_key
def per_user_key(request: Request) -> str:
return build_cache_key(request, request.state.user_id)
default_key_builder(request) becomes build_cache_key(request).
- Extra components go through
escape_key_component, so they cannot inject the separator either.
- Update the docs example to use it.
Additive; no key changes for existing routes.
Problem
A custom
key_builderthat adds a dimension (user ID, tenant, locale) has to rebuild the whole default key by hand. The per-user example in HTTP_CACHING.md did that and repeated #230: it joined the rawHostheader and path with|||. Every hand-rolled builder is one forgottenescape_key_componentaway from the same key-poisoning bug.Proposal
Add a public helper that builds the default key and appends extra components, encoding every component:
default_key_builder(request)becomesbuild_cache_key(request).escape_key_component, so they cannot inject the separator either.Additive; no key changes for existing routes.