Caching
Keeping an answer around to reuse for the same request
- Caching is a way of keeping an answer you already produced once and pulling it back out with no computing when the same request comes in again.
- When it hits, both the wait and the cost drop sharply, since no computing happens at all.
- The very first request, and any request never seen before, stay just as slow. Only the second time onward speeds up.
- The moment the original changes, whatever was kept becomes a wrong answer instantly. Deciding when to throw it out is half the job of caching.
- An answer that differs from person to person is pointless to keep. The trick is keeping only what would go out the same to everyone.
Contents
1The analogy
Next to a permit office counter sits a rack stacked with copies of the forms people ask for most. Instead of running the printer every time someone shows up, the clerk just hands over one from the rack. It got printed just once, and every visit after that has no wait at all.
Caching is that rack of forms. When the same request comes in again, it hands over the answer that's already sitting there. If a form isn't on the rack, that's when the printer runs — and while it's running, it prints a few extra copies and stocks the rack.
The rack only has so many slots, so a form that rarely gets asked for has to give up its spot, and when a form gets revised, whatever's left in the stack has to be thrown out entirely. Not throwing it out means handing out the old version forever.
2In detail
It's the second time that gets faster
Caching isn't a technique for making computation faster. It's a technique for skipping computation. That's why it does nothing at all for a question nobody has ever asked. The first request gets computed as usual to produce an answer, with one extra step: a copy of that answer gets kept.
The gap opens up starting with the second request. An answer that used to take a few seconds arrives in an instant, and because no request even goes out to the service, usage doesn't tick up either. The more often the same question comes in, the more this difference piles up.
That's why caching's score gets measured as "how often did it hit." If nine out of ten requests came straight off the rack, that's a well-chosen setup; if it's only one out of ten, all you've bought is the trouble of maintaining the rack.
What can actually be kept on the rack
Only a genuinely identical request can be answered with the same thing again, and the bar for "identical" here is fairly strict. A single different character, or even a slightly different start to the conversation, counts as a different request. That's why an answer to a frequently asked question, a summary of a commonly used document, an intro blurb that always goes out with a listing — anything that goes out the same to everyone — fits well on the rack.
An answer that differs from person to person, on the other hand, is useless to keep. A conversation about your own order history, a question about a file you just uploaded — these don't belong. Watch out too for an answer that has someone's personal information mixed into it accidentally getting handed to someone else. Checking whether an answer would go out the same to anyone is the habit that matters here.
There's one exception: rewriting only the front part of a request rather than the whole answer. A service that sends the same long rules or document at the front of every request can keep the state of having already read that front part and reuse it on the next request. The question tacked onto the end still varies person to person, but since the front part is always the same, that alone saves real time and usage.
Deciding when to throw it out is half the job
A kept answer goes stale over time. If the wording of a notice changed but the rack still has the old answer sitting on it, the service starts handing out a wrong answer very quickly. This is the single most common caching accident.
So an expiration gets set. Content that rarely changes gets a long one; content that shifts constantly gets a short one. Sometimes things get wired up so that fixing the original immediately clears out anything related to it. Without mapping out ahead of time what to throw away when something changes, it becomes very hard later to track down where an old answer is still hiding.
The rack only has so many slots
The space where things get kept isn't free either. Once the slots fill up, something has to be pushed out to make room for something new, and usually whatever hasn't been requested in the longest goes first. That's why a question that only comes in once in a while can get kept and still be gone again by the next time it comes up.
The storage spot often overlaps in several places too — inside the user's own device, in front of the service, at the point where the model itself gets called — each layer kept separately for speed, but each one is also another place an old answer can be hiding. That's exactly why it gets confusing which layer's rack needs clearing when a wrong answer keeps showing up.
3More precisely
There are broadly two approaches to keeping things. One hands back a kept answer only when the request text matches character for character; the other hands one back when the meaning is close enough. The second raises the hit rate a lot, but it also raises the risk of handing a wrong answer to a question that only looks similar. Deciding how close is close enough to count as the same question is the crux of that approach.
The analogy breaks down in one place. A paper form shows its age when it gets revised — the look changes and it's obvious. A kept answer can go stale while looking perfectly fine on the outside. Forms get stocked and pulled by hand, but caching mostly runs on its own, so checking what's sitting where takes deliberate effort. Above all, handing someone a form takes one copy off the stack, but a kept answer stays exactly where it was no matter how many times it gets pulled out. That means a wrong answer, once it gets in, doesn't disappear on its own — it keeps going out until someone clears it.
4Try it yourself
5Common misconceptions
It's easy to think turning on caching automatically makes things faster, but actually it only helps when the same request repeats, so a service where every question is different just gets extra upkeep for nothing.
It's easy to think a kept answer is always correct, but actually an old answer can sit there after the original changed and hand out a wrong answer very quickly.
It's easy to think this is the AI remembering your question, but actually — unlike remembering a conversation — it's just holding onto one copy of the answer for one exact request.
7One-line summary
In shortCaching is a rack stocked with the answers that go out most often, and the speed it buys from the second time on comes with the job of deciding when to throw each one out.
Spotted an error or have a better analogy? Suggest an edit · Last updated2026-09-02