liveBook · Manning

Caching

As explained in Grokking Software Architecture

Caching is the technique of temporarily storing reusable data or results to reduce latency or repeated computation.

A cache is a fast, temporary storage layer for data or results that would otherwise need to be fetched from a database or recalculated. Check it first; when the result is missing, do the slower work and save the answer for next time. section 2.4.4

A dashboard without repeat work

A dashboard summary makes three slow database queries on every request. With 100 users, that means 300 queries. A cache can serve a saved summary on a hit; on a miss, the system runs the queries and stores their result. One example sets the cached result to expire after ten minutes. section 2.4.4

Caching trades extra complexity and less-live data for speed: the cache is another component to manage, deploy, and monitor, and users may not see changes immediately. Reusing an expensive result can also reduce repeated database work enough to delay adding servers. section 2.4.4 section 10.6

Figure 2.8 By checking a fast cache first, the system avoids expensive database queries. A Cache Miss creates a temporary delay to fetch and save data, but each subsequent request becomes nearly instantaneous.

The diagram shows the cache-first path: a miss adds a temporary delay, while later requests can use the saved result. section 2.4.4

For lower latency, a system can use multiple cache levels: a local cache in the application server’s memory and a shared distributed cache. The local cache avoids a network trip, while the shared cache serves the wider system. section 10.6

How Grokking Software Architecture covers it

How deep it goes
Defines cache hits and misses and walks through a database-backed example, while noting complexity and consistency costs.
Examples
Uses a dashboard summary with three database queries and contrasts local with shared caching.
What you can do after
Apply a cache-first pattern to reuse results and reduce repeated computation or database queries.
How it connects
Connects caching to database performance, consistency, distributed systems, and scaling out.

Also explained in

Compare how 49 books explain caching →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.