Load a cached value using stale-while-revalidate semantics.
This helper is server-side only and is intended for caching internal async dependencies such as auth or metadata lookups.
Semantics:
loader(), store the value, return itloader(), store the value, return itHow long a cached value is considered fresh (no revalidation).
Defaults to timedelta(0) so every access triggers a background
revalidate while still returning the cached value instantly. Values
above :data:MAX_CACHE_TTL are clamped to the backend maximum.
Total lifetime of a cached entry. After this, the next access
blocks on the loader. Defaults to :data:MAX_CACHE_TTL (24 h by
default). Values above :data:MAX_CACHE_TTL are clamped to the
backend maximum.
Optional Pydantic model class. When provided, values are
serialized via model_dump(mode="json") before storage and
deserialized via model.model_validate() on read.