This repository provides a complete reference implementation of this architecture:
Cloudflare Worker (Serverless)
A distributed, serverless approach using Cloudflare Workers.
- Pros: Global distribution by default, zero server management, sub-millisecond setup.
- Tech: JavaScript, Cloudflare KV/Cache API, Wrangler.
Regardless of the implementation, the flow remains the same:
┌───────────┐ ┌─────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ Client │──────▶│ Cloudflare │──────▶│ Revalidation │──────▶│ Origin API │
│ Browser │◀──────│ CDN Edge │◀──────│ Proxy/Worker │◀──────│ media.giphy.com │
└───────────┘ └─────────────────┘ └──────────────────┘ └──────────────────┘
│ │
Caches based on In-memory or KV
Cache-Control cache + ETag
headers from revalidation
revalidation layer logic
- To run the Worker: See
/worker/README.md.
Both solutions inject X-Debug-* headers to provide insight into the caching flow:
X-Debug-Cache:HIT,MISS,STALE,REVALIDATED,PURGED.X-Debug-Origin: The actual status code returned by the upstream origin.X-Debug-ETag: The ETag value used for the revalidation check.
This is a reference implementation. See repository license for details.