What this page explains

For: anyone who builds or runs a service that reads from a database. After this page you can say what a cache does and estimate how much load it removes.

Cache
A small, fast store that keeps copies of recent answers.
Hit
A read that the cache answers from its copy.
Miss
A read the cache cannot answer, so it asks the database.
Hit rate
The share of reads that are hits.

One case first

A report page gets 120 reads each second. The cache answers 9 of every 10 of them. Only the misses reach the database: 120 reads times one tenth is 12 reads each second.

The rule: the database sees only the reads the cache misses.

Change it and watch

Reads that reach the database:

Try this: set the hit rate to 0, then to 100, and compare what the database sees.

Follow one read

flowchart LR
  client[client]:::k1 --> cache[(cache)]
  cache --> db[(database)]
client (now) --> cache --> database
The client asks the cache first.
flowchart LR
  client[client]:::k2 --> cache[(cache)]:::k1
  cache -->|miss| db[(database)]
client --> cache (now, a miss) --> database
The cache has no copy. This is a miss, so it asks the database.
flowchart LR
  client[client]:::k2 --> cache[(cache)]:::k2
  cache --> db[(database)]:::k1
  db -->|answer, kept| cache
client --> cache --> database (now) --answer, kept--> cache
The database answers. The cache keeps a copy of the answer.
flowchart LR
  client[client]:::k2 --> cache[(cache)]:::k1
  cache -->|hit| client
  db[(database)]
client --> cache (now, a hit) --> client; the database is not asked
The next read for the same report is a hit. The database is not asked.