Why does a cache make reads faster?
Options
- It compresses the database to make it smaller
- Hot data sits in fast storage, skipping slower work (Correct option)
- It deletes old rows from the main database
- It encrypts the data before it is read back
Answer
It keeps copies of frequently used data in fast storage (usually memory), so you skip slower work like a database query
Why
Reading from memory takes microseconds; a database query or an external API call can take milliseconds or more.
A cache stores results you already computed or fetched, so the next request gets them instantly.
The hard part is freshness: cached data can be outdated, so entries get an expiry time (TTL) or are deleted when the data changes.
Remember
Cache = fast copy of data you will need again.