Gateway Response Cache
Use kt cache to inspect the response cache selected by the current
KEEPTRUSTS_LLM_CACHE_* environment. The command opens the configured backend
directly; it does not query a running gateway.
Command summary
| Command | Result |
|---|---|
kt cache stats | Show the selected backend and whether caching is enabled. The filesystem backend also reports entries, size, hit/miss counts, evictions, and warm-up state. |
kt cache list --top 20 | List the most recently accessed filesystem entries. |
kt cache list --top 20 --by-size | List the largest filesystem entries. |
kt cache inspect <key> | Read metadata for one exact cache key. |
kt cache clear | Confirm interactively, then clear the selected backend. |
kt cache clear --yes | Clear without the prompt; use only in an intentional maintenance workflow. |
list is filesystem-specific. stats prints a backend summary for every
backend, but detailed entry statistics are available only for the filesystem
backend. An empty list on another backend is not evidence that the remote
cache has no entries.
Inspect the active cache
Run commands with the same environment used by the gateway:
export KEEPTRUSTS_LLM_CACHE_BACKEND=filesystem
export KEEPTRUSTS_LLM_CACHE_DIR="$HOME/.keeptrusts/cache"
kt cache stats
kt cache list --top 10 --by-size
The filesystem backend defaults to a 500 MB maximum when
KEEPTRUSTS_LLM_CACHE_MAX_BYTES is not set. Treat the command output as the
source of truth for the environment you actually invoked.
To inspect an exact key:
kt cache inspect '<exact-cache-key>'
The inspection output contains metadata such as status, body size, stored
time, key version, header count, and content type when present. It does not
print the cached response body. list truncates long keys for display, so a
truncated row is not valid input to inspect; obtain the complete key from the
approved cache diagnostic source.
Clear cache entries safely
Clearing affects the backend selected by the command's environment:
kt cache stats
kt cache clear
kt cache stats
For remote backends, a Cache cleared. message and zero exit status mean that
the CLI dispatched the clear operation; they do not prove that every remote
delete succeeded. The Redis, Valkey, object-store, and Qdrant adapters can log
individual clear failures without returning them to the command. Verify the
result with approved backend telemetry and a representative cache miss.
Before clearing a shared Redis, Valkey, object-store, or Qdrant backend, confirm
that the configured URL, bucket, prefix, collection, and credentials identify
the intended environment. --yes removes the interactive guard; it does not
add a dry run or restrict the operation to one gateway.
Use a cache buster for a controlled logical rollover when deleting shared
entries is not the desired operation. Replace release-current with a new
deployment-specific value for each rollover:
export KEEPTRUSTS_LLM_CACHE_BUSTER="release-current"
The gateway incorporates the buster into cache-key behavior. Changing it makes older entries stop matching without asserting that the old backend objects were deleted.
Configuration checklist
The cache runtime supports memory, filesystem, Redis, Valkey, S3, GCS, and
Qdrant backends. Configure the selected backend through the matching
KEEPTRUSTS_LLM_CACHE_* variables, then:
- Run
kt cache statsin the gateway environment. - Start or restart the gateway with that same environment.
- Send a representative request twice when your policy permits caching.
- Inspect gateway response metadata and cache metrics rather than inferring a hit from latency alone.
- Re-run
kt cache statsfor filesystem counters.
Do not cache sensitive or regulated content unless your retention, encryption, and access policies explicitly allow it.
Troubleshooting
| Symptom | Check |
|---|---|
stats shows an unexpected backend | Compare the shell environment with the gateway service environment. |
Filesystem list is empty | Confirm the directory, cache enablement, request eligibility, TTL, and cache buster. |
| Remote backend has no detailed statistics | This CLI view exposes detailed entry statistics only for the filesystem backend; use the backend's approved operational telemetry. |
| Remote clear prints success but entries remain | Inspect CLI and backend logs, confirm connectivity and credentials, then verify the selected prefix, bucket, or collection. The command exit status alone is not proof of remote deletion. |
| A repeated request misses | Check model, request fields, route, policy eligibility, TTL, key version, and cache buster. |
inspect cannot find a key | Confirm the complete, untruncated key and the same cache backend and environment. |