LLM prefix cache replay
Replays an LLM request trace through a KV prefix cache to report hit rate, hit tokens and final contents.
Claude's review
7/10 Very specific, correct S3FIFO and prefix hit replay rules with pitfalls, narrow to one kind of task.
We asked Claude the question you would ask: would I be glad I installed this? We only sell skills it rates 7 or higher.
In detail
Replay an LLM inference request trace (Mooncake / vLLM / SGLang hash_ids format) against a block-level KV prefix cache and compute hit statistics. Use when given a request trace plus cache configuration and asked for hit rate, hit tokens, or final cache contents. Covers the longest-contiguous-prefix semantics that distinguishes KV prefix caching from full-prompt prompt caching, the policy-specific residency and eviction rules (LRU, LFU, S3FIFO), and the partial-last-block accounting rule.
How you use it
- Add it to your pack, then download your pack (1 credit).
- In Claude, open Customize > Skills and upload the zip. Code execution needs to be on under Settings > Capabilities.
- Ask Claude for the job in your own words. It uses the skill when your request matches what it does. Step by step guide
Safety check
Nothing risky found: no hidden instructions, no download and run, no reading of saved passwords or keys.
An automated scan lowers risk but cannot promise zero risk. How we check skills
Preview
The first lines of SKILL.md
---
name: prefix-cache-replay
description: Replay an LLM inference request trace (Mooncake / vLLM / SGLang hash_ids format) against a block-level KV prefix cache and compute hit statistics. Use when given a request trace plus cache configuration and asked for hit rate, hit tokens, or final cache contents. Covers the longest-contiguous-prefix semantics that distinguishes KV prefix caching from full-prompt prompt caching, the policy-specific residency and eviction rules (LRU, LFU, S3FIFO), and the partial-last-block accounting rule.
---
# Overview
Modern LLM serving systems — vLLM, SGLang, Mooncake — pack the KV tensors of a prompt into fixed-size blocks of `block_size` tokens (typically 512). The cache is keyed by a block hash where each hash encodes both the block's own token content and the content of every block before it in the prompt. Two requests that share the first K conversation turns therefore share the first K block hashes, and the cache can reuse those blocks without recomputing attention.
This is **block-level prefix caching**. It is not the same thing as full-prompt prompt caching (Anthropic, OpenAI), where the cache stores whole prompts and looks them up by exact match. Prefix caching reuses partial prompts; prompt caching does not.
# Longest-prefix hit semantics (policy-independent)
Let a request have `hash_ids = [h_0, h_1, ..., h_{n-1}]` and `input_length = L`.
The prefix hit length is the largest integer `k` such that `h_0, h_1, ..., h_{k-1}` are **all resident in the cache** at the time the request arrives.
- `k` must start at index 0. Reuse of `h_2` when `h_0` is absent does not count.
- The scan stops at the first miss. No skip-ahead, no set intersection.
- Hit tokens for the request = `min(k * block_size, L)`. The `min` handles the last partial block (when `L` is not a multiple of `block_size`). Always apply it — do not return `k * block_size` unclamped.
After the prefix scan, every block in `hash_ids` — hit or miss — is accessed against the eviction policy in order. Hits update policy state (recency / frequency); misses admit the block and may trigger evictions. What "resident" means is policy-specific, as spelled out below.
# S3FIFO (Yang et al., SOSP 2023 — "FIFO queues are all you need")
S3FIFO replaces LRU / LFU with three static FIFO queues plus a per-block saturating frequency counter. Three things to know:
- **Three queues, all FIFO** (tail = most recently added):
- **Small (S)** — sized at `round(capacity * small_ratio)`. Newly admitted blocks land here. Default `small_ratio = 0.1`.
- **Main (M)** — sized at `capacity - small_cap`. Holds the working set promoted from S.
- **Ghost (G)** — same size as main; **metadata only**. Remembers recently evicted block hashes so a re-access can fast-track to M. **Ghost entries are NOT resident** — a prefix that lands in G is a miss for hit-token accounting.
- **Each block carries a saturating frequency counter** `freq` clamped to `[0, max_freq]`. Default `max_freq = 3`. Whenever a resident block is accessed, increment `freq` and clamp.
- **Admission and eviction differ between queues**, described below.
## Access rule (per `h` in a request's `hash_ids`)
If `h` is currently in S, increment its freq (saturated). If `h` is in M, increment its freq (saturated). If `h` is in G, remove it from G and admit it to the tail of M with freq 0 (this is the canonical Yang et al. variant — some papers admit with freq 1; stick to 0 unless the config says otherwise). Otherwise (`h` is brand new), admit it to the tail of S with freq 0.
The check on a request's prefix is a residency check (S ∪ M); the per-block access actions above happen for **every** `h` in `hash_ids`, not just the prefix portion.
...From benchflow-ai's repository, Apache-2.0 licence.
Related skills
-
Checked
Council of AI models
Asks several AI models the same question separately, compares their answers and gives you the best one.
7/101 credit -
Checked
RAG evaluation
Measures how well a RAG system retrieves and answers, with test questions, metrics and chunking advice.
8/101 credit -
Checked
AI automation planner
Works out which manual work in your business to automate first, then designs the system, tools and safeguards.
7/101 credit -
Checked
LangGraph agent design
Guides LangGraph builds through topology, checkpoint and human review choices so agents survive failures.
7/101 credit -
Checked
Agent system design
Asks staged questions to design agent pipelines and sub agents, so you only add agents where they help.
7/101 credit -
Checked
Subagent model routing
Chooses the model, effort level and cascade for each subagent by cost per finished task, keeping loops safe.
7/101 credit