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: object

Persist LLM responses through encrypted secure objects.

The cache derives CacheKey values from LLMRequest content and persists LLMResponse payloads through secure_object_repository_for_active_bucket().

Parameters:

root_dir (Path | None) – Optional logical cache partition override.

build_key(request, provider, model)[source]

Derive a CacheKey from the request.

Parameters:
Return type:

CacheKey

Returns:

Deterministic CacheKey components.

read(request, provider, model)[source]

Read a cached response, if present.

Parameters:
Return type:

LLMResponse | None

Returns:

Cached LLMResponse when present, otherwise None.

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 at SensitivityClass DIAGNOSTIC class 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:
Return type:

CachedEntry

Returns:

Persisted CachedEntry model.

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:

CacheStats

Returns:

CacheStats with 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:

int

Returns:

Number of removed cache objects.

Raises:
  • LLMCacheError – When a cache

  • entry cannot be parsed during iteration.