Caching is the single most impactful performance optimization for SaaS applications — it reduces latency, lowers origin load, and improves user experience. Cloudflare provides a multi-layered caching stack (CDN, Workers Cache API, KV, D1 query caching, Cache Reserve) that can serve content from edge locations within 30ms globally. This guide covers caching strategies at each layer, with practical patterns used at tanstackship.com.

The Caching Stack

Cloudflare's caching infrastructure has multiple layers, each with different characteristics:

Layer

Latency