Image: CloudFlare
Cloudflare has launched Workers Cache, a dedicated frontend caching layer built specifically for Cloudflare Workers. With this release, Workers can act as their own origin. They can now also benefit from more efficient edge caching. The direct advantage for developers is faster response times and lower operating costs.
How the Two-Layer Cache Architecture Works
Workers Cache includes two distinct layers. The lower layer sits at the edge data center closest to the user. The upper layer aggregates requests from across the globe. That global aggregation produces a significantly higher cache-hit rate.
When a request hits the cache, Workers does not need to execute at all. The response returns directly. When a request misses the cache, Workers executes once and populates both the upper and lower layers simultaneously.
Cache Behavior and HTTP Header Support
Cache behavior is controlled by standard HTTP Cache-Control response headers. The feature also supports Stale-While-Revalidate (SWR). With SWR, a stale response returns immediately while the cache refreshes in the background. As a result, users never perceive any delay.
Additionally, Workers Cache supports the Vary header for content negotiation. Developers can use Cache-Tag for targeted cache invalidation. Multi-tenant security isolation is also available, which is useful for dynamic responses that require user authentication.
Four Key Advantages for Developers
1. Lower Cost and Latency
First, Workers Cache significantly reduces both cost and latency. Cache hits require no Worker execution and no CPU billing. Responses are also faster.
2. Better Dynamic Content Performance
Second, it improves dynamic content performance. This makes it ideal for server-side rendering scenarios. Developers can keep dynamic rendering active while achieving near-static performance.
3. Simpler Multi-Tenant and Auth Scenarios
Third, it simplifies multi-tenant and authenticated use cases. Developers no longer need to disable caching because of Authorization headers. Instead, they can achieve secure user-level cache isolation through ctx.props.
4. Precise Cache Invalidation
Fourth, Workers Cache provides powerful invalidation. Write-time invalidation lets developers purge specific caches with precision using tags whenever data changes.
Availability, Limits, and Framework Support
Workers Cache is available to developers on all Cloudflare subscription plans. To enable it, developers simply add the configuration to their Wrangler setup. The current response body size limit is 512 MB. Cloudflare plans to adjust this limit based on subscription tier in the future.
Cache metrics are integrated into the Workers Observability dashboard. Developers can use it to review hit rates, updates, and bypasses. Cloudflare also provides an official cacheCloudflare integration for the Astro framework. Support for other frameworks, including Next.js and TanStack Start, is currently in development.
Support Our Threat Intelligence
If you find our CVE report and cybersecurity news helpful, consider supporting our work.