Cache-Control Headers
Cache-Control is an HTTP response header that tells browsers, CDNs, and proxies whether and how long a response may be cached. Directives such as max-age, s-maxage, private, no-store, and stale-while-revalidate control freshness and sharing for every cached copy.
Technical Architecture & Deep-Dive
Caching behavior is negotiated through headers. `max-age=60` lets any cache reuse a response for 60 seconds, `s-maxage` applies only to shared caches like CDNs, and `private` restricts caching to the end user browser. `no-store` forbids caching entirely, which is essential for sensitive data.
Edge gateways can override or add Cache-Control headers on third-party API responses that lack them, enabling safe caching of public data while ensuring personalized responses are never shared between users.
Key Architectural Benefits
Edge-Cacheable API Response Header
Cache-Control: public, max-age=30, s-maxage=300, stale-while-revalidate=600Implement Cache-Control Headers at the Edge
Deploy lightweight API aggregation, edge caching, and secret injection in minutes without Docker containers or complex servers.
Frequently Asked Questions
Q:What is the difference between max-age and s-maxage?
max-age applies to all caches including browsers. s-maxage overrides it for shared caches such as CDNs and edge proxies only.
Related Architecture Concepts
Edge Caching is the practice of storing computed API responses on globally distributed Point of Presence (PoP) servers situated geographically close to users. By serving cached responses directly from edge memory, requests achieve sub-10ms latencies while offloading 95%+ of traffic from origin databases.
Stale-While-Revalidate (SWR) is an HTTP cache control extension that instructs the edge to serve an existing cached (stale) response instantly to the client, while asynchronously initiating a background fetch to refresh the cache. Users experience zero latency wait time while always receiving fresh data.
An ETag, or entity tag, is an HTTP response header containing a version identifier for a resource. Clients send it back in an If-None-Match header, and if the resource has not changed, the server replies with 304 Not Modified and no body, saving bandwidth.
A cache key is the unique identifier a cache uses to store and look up a response. It is typically built from the request URL and may include query parameters, selected headers, or user attributes. Two requests with the same cache key receive the same cached response.
Ready-to-Use Edge Recipes
To rest api edge cdn caching guide, set cacheTtlSeconds on a GET pipeline targeting https://jsonplaceholder.typicode.com/users/{{query.userId}}. Identical query strings reuse Cloudflare caches.default before upstream sees traffic.
REST API rate limits hit fast from Frontend / Web. Cache 300s on GET calls where the query string scopes the response.