MEPX
Chapter 4 of 10All chapters

Chapter 4 of 10

Caching

The cheapest speedup and the subtlest bugs.

Where caches live

In the browser, at a CDN, in front of the application, inside it, and in front of the database. Each layer removes work from everything behind it.

  • Cache what is expensive and read often, not everything.
  • A cache hit rate below about 80 percent rarely justifies the complexity.

Invalidation

The hard question is when a cached answer stops being true. Short expiry times are simple and slightly stale; explicit invalidation is exact and easy to get wrong.