Prefix caching
Same beginning, one copy.
Two requests arrive with the same first 512 tokens: the same system prompt. Same tokens at the same positions give exactly the same k and v. Paged as before, each gets its own copy: the same numbers written twice.
The prefix arithmetic, once
Position ‘s key and value are functions of tokens , so two requests can share cache exactly for their longest common prefix and nothing past it. A shared prefix of tokens across requests costs tokens of cache instead of , and a newcomer prefills tokens:
In a chat of turns with question and answer , prefill without caching sums to and with it to . SGLang’s RadixCache is the tree, reference counts pin the pages of running requests, eviction is least-recently-used over unreferenced nodes, and schedule_policy=lpm orders the waiting list by matched length.