cache-pressure
Measure how much context a prefix cache actually retains under overflow pressure — not what the engine advertises.
The advertised KV cache size is an active-request planning budget, not a ceiling on cacheable content. Hybrid layouts (MLA + sparse-attention + recurrent-state groups) pack cached blocks denser than that reservation, and cache-management defects can waste the headroom with duplicate blocks and unreachable replay tails. This tool quantifies the real number, so you can tell a healthy cache from a leaking one on any OpenAI-compatible deployment.
How it works
1. capacity the engine's advertised KV size in tokens, provided manually
with --kv-size (required)
2. calibrate tokens/char for this tokenizer at the target length
(length-dependent, iterates to convergence), then the
hit/miss threshold: one probe context sent cold (miss
baseline) and again from cache (hit baseline) — the
threshold is their midpoint
3. hydrate N unique ~8K-token contexts sequentially (max_tokens=1,
prefill-only — the full context is committed regardless)
N = ceil(capacity/8000)+5, so the cache overflows
4. verify re-send each context in reverse order (newest first),
classify hit/miss by TTFT against the calibrated threshold
→ the first miss is the oldest evicted context = the real
retained capacity. Stops there: under LRU everything older
is evicted by construction.
Contexts are seeded random word-orders (unique per salt within a run, byte-identical across runs) so no context rides on another's cached content, and two runs (e.g. before/after a fix) replay the same text.
The default 8K context size keeps the measurement granularity fine; pass
--context-tokens to coarsen or refine. The hit/miss threshold is
calibrated at runtime from measured cold-prefill and cache-hit TTFT, so it
stays valid regardless of engine speed — override with --hit-threshold
only if you have a reason.
Usage
Run directly from PyPI — no install needed:
# point --base-url at your OpenAI-compatible endpoint; the model is
# auto-detected via GET /models (pass --model to override)
uvx cache-pressure --base-url http://my-server:8000/v1 \
--kv-size <ADVERTISED_KV_CACHE> --output run.json
# A/B two runs
uvx cache-pressure --compare fix.json control.json
Small sanity check (3 contexts, all hits):
uvx cache-pressure --base-url http://my-server:8000/v1 \
--kv-size <ADVERTISED_KV_CACHE> --num-contexts 3
needle-test — companion correctness check
The retention number means nothing if the engine is broken. This sweeps increasing context lengths (default 50K/100K/200K/300K/450K), hides a needle sentence at 0.8 depth in each unique haystack, and requires the model to output the exact secret code — proving long-context retrieval is intact end-to-end.
uvx needle-test --base-url http://my-server:8000/v1 # full sweep (50K -> 450K)
uvx needle-test --base-url http://my-server:8000/v1 \
--lengths 50000,100000 # subset
needle-test calibrates against its own target lengths and does not need
the advertised capacity (it only needs to stay under the engine's
max_model_len). The model is auto-detected like in cache-pressure; pass
--base-url/--model to point it at your endpoint.
Development
git clone <repo> && cd cache-pressure
uv sync # create .venv with the project installed
uv run python tests/test_cache_pressure.py # no cluster needed
# exercise the console scripts against the local checkout
uvx --from . cache-pressure --help
uvx --from . needle-test --help
Interpreting results
retained % capacity can exceed 100% — that is not a bug. The
advertised capacity is a worst-case reservation per active context token;
cached content (constant-size recurrent state, bounded sliding-window
groups, deduplicated blocks) packs denser, so the cache can physically hold
more context than the budget implies. One fixed deployment retained ~147%
of advertised capacity with zero evictions at 39K granularity; the
pre-fix engine kept ~52-65%.
Metadata
Release files for cache-pressure 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cache_pressure-0.1.0.tar.gz | 32.7 kB | Without provenance | Details for cache_pressure-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cache_pressure-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for cache_pressure-0.1.0-py3-none-any.whl |
Total release size: 47.1 kB
Release files / cache_pressure-0.1.0.tar.gz
| Download URL | cache_pressure-0.1.0.tar.gz |
|---|---|
| Size | 32.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3fac3cc6c3d68d76834e65d6e3ad8191b2ddd66d4dffd3750cb8a204e8a7866f
|
|
BLAKE2b-256 checksum How to use checksums |
a766aa337c814f7f65e52938faa30c46b8067fba4e390787146ca8477aba245f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / cache_pressure-0.1.0-py3-none-any.whl
| Download URL | cache_pressure-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cbb71e69fa4efb606fc4d19b45df6b0e134a550e641219af9888b1436e7d4afc
|
|
BLAKE2b-256 checksum How to use checksums |
51b2870c4280d7797ed72e07153a0ef688fca6e31975ddf0dfdcb67fddd6b5ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for cache-pressure 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.