A Cache is a high-speed data storage layer which stores a subset of data, typically transient in nature, so that future requests for that data are served faster than accessing the data's primary storage location (the database). Caching is one of the single most impactful techniques for improving system performance.
A database query might take 50-200ms (involving disk reads, SQL parsing, and network round trips). A cache lookup in Redis or Memcached takes 0.1-1ms (pure in-memory access). That is a 100x to 1000x speedup.
If 80% of your application's traffic is reading the same popular data (the homepage, trending posts, a product catalog), caching that data in memory eliminates millions of unnecessary database queries per second.
How does data get into the cache in the first place?
The application manages the cache manually.
Every write goes to the cache AND the database simultaneously.
The application writes only to the cache. The cache asynchronously writes to the database in the background (in batches).
Caches have limited memory. When the cache is full and a new item needs to be stored, an old item must be evicted. The eviction policy determines which item to remove.
Cache-Control and ETag manage this.