aeat.adapters.outbound.llm._cache module¶
Encrypted content-addressed cache for LLM responses.
Each CachedEntry is stored under
LLM_CACHE_NAMESPACE as an encrypted
secure object with SensitivityClass
DIAGNOSTIC classification so operator-identifying inputs are redacted
before persistence.
- class LLMCache(root_dir=None)[source]¶
Bases:
objectPersist LLM responses through encrypted secure objects.
The cache derives
CacheKeyvalues fromLLMRequestcontent and persistsLLMResponsepayloads throughsecure_object_repository_for_active_bucket().- Parameters:
root_dir (
Path|None) – Optional logical cache partition override.
- build_key(request, provider, model)[source]¶
Derive a
CacheKeyfrom the request.- Parameters:
request (
LLMRequest) – StructuredLLMRequest.provider (
LLMProvider) – EffectiveLLMProvider.model (
str) – Effective model for the request.
- Return type:
- Returns:
Deterministic
CacheKeycomponents.
- read(request, provider, model)[source]¶
Read a cached response, if present.
- Parameters:
request (
LLMRequest) – StructuredLLMRequest.provider (
LLMProvider) – EffectiveLLMProvider.model (
str) – Effective model for the request.
- Return type:
- Returns:
Cached
LLMResponsewhen present, otherwiseNone.- Raises:
LLMCacheError – When the cached
payload is present but cannot be parsed. –
- write(request, response)[source]¶
Write a response to the cache and return the stored entry.
The serialised payload is routed through the substrate’s
redact_structured()helper atSensitivityClassDIAGNOSTICclass before persistence (the CACHE-class default policy has an empty rule set because most caches are public reference data; the LLM cache carries identity-bearing inputs and therefore adopts the DIAGNOSTIC rule set, mirroring the run-trace sink’s discipline). The redacted payload is stored as an encrypted SQL secure object rather than a materialized JSON file. The redaction is idempotent — re-reads of an already-redacted entry stay correct because the cache carries the redacted text only.- Parameters:
request (
LLMRequest) – StructuredLLMRequest.response (
LLMResponse) – PublicLLMResponseto persist.
- Return type:
- Returns:
Persisted
CachedEntrymodel.- Raises:
LLMCacheError – When redaction
produces a non-dict result or the storage write fails with an –
OS-level error. –
- stats()[source]¶
Return encrypted cache counts as a
CacheStats.- Return type:
- Returns:
CacheStatswith aggregate entry count and total decrypted JSON byte size for this logical cache partition.
- prune()[source]¶
Delete every cached entry in this logical partition.
- Return type:
- Returns:
Number of removed cache objects.
- Raises:
LLMCacheError – When a cache
entry cannot be parsed during iteration. –