All glossary terms

Efficiency

Eviction policy

What a full prefix cache forgets when a new family needs the space. Hit rate is capped by the share of families the scratch can keep resident at once.

A prefix cache is a fixed amount of card memory holding copies of prompt preambles, and when it fills, something leaves. The policy that chooses the eviction decides whether the cache is serving the traffic or its own history: families that stop appearing should leave fast, families that are about to return should stay, and both rules only work if someone measured which families actually return.

The first number is capacity, not cleverness. The scratch holds whole copies and nothing between: a partially resident preamble is not a hit, so the copy count is the floor of scratch size over copy size. Routing determines how many distinct families a card must serve; the scratch determines how many it can keep. When demand for residency exceeds capacity, the hit rate collapses toward the ratio of kept copies to demanded copies, no matter how the router behaves.

The interview answer pairs the two levers with their failure modes. Grow the scratch or route more tightly until demanded copies fit within held copies; otherwise eviction dominates the hit rate and the fix is capacity or routing, not the eviction algorithm. Choosing least-recently-used is the sensible default, but it is the small lever - which is why the copy arithmetic comes first and the policy argument second.

A worked example

A card keeps an 8 GB prefix scratch. A resident preamble copy of a 1,200-token prompt family is 384 MB. Traffic touches 20 families per card today.

  1. Capacity: 8 GB x 1,000 = 8,000 MB, and 8,000 / 384 = 20.8, so the scratch holds 20 whole copies.
  2. At a 20-family working set, every arrival can hit a resident copy: 20 kept / 20 demanded = 100 percent.
  3. When traffic widens to 25 families, capacity is short 5 copies: the best a policy can do is 20 / 25 = 80 percent, and each miss re-prefills a 384 MB copy.

The scratch holds 20 whole copies out of 25 demanded, capping the hit rate at 80 percent - a policy choice between what stays, but an arithmetic ceiling on what is possible.

Where this shows up

Test yourself

Related terms