megachangelog
Feature

Workers Fetch API can override Cache Rules

Cloudflare Workers can now programmatically override Cache Rules using the cf object in fetch() commands, enabling dynamic per-request cache customization based on request properties and business logic. This includes control over cache-everything behavior, TTL values, status-based TTLs, cache keys, and cache tags.

You can now programmatically override Cache Rules using the cf object in the fetch() command. This feature gives you fine-grained control over caching behavior on a per-request basis, allowing Workers to customize cache settings dynamically based on request properties, user context, or business logic.

How it works

Using the cf object in fetch(), you can override specific Cache Rules settings by:

  1. Setting custom cache options: Pass cache properties in the cf object as the second argument to fetch() to override default Cache Rules.
  2. Dynamic cache control: Apply different caching strategies based on request headers, cookies, or other runtime conditions.
  3. Per-request customization: Bypass or modify Cache Rules for individual requests while maintaining default behavior for others.
  4. Programmatic cache management: Implement complex caching logic that adapts to your application's needs.

What can be configured

Workers can override the following Cache Rules settings through the cf object:

  • cacheEverything: Treat all content as static and cache all file types beyond the default cached content.
  • cacheTtl: Set custom time-to-live values in seconds for cached content at the edge, regardless of origin headers.
  • cacheTtlByStatus: Set different TTLs based on the response status code (for example, { "200-299": 86400, 404: 1, "500-599": 0 }).
  • cacheKey: Customize cache keys to control which requests are treated as the same for caching purposes (Enterprise only).
  • cacheTags: Append additional cache tags for targeted cache purging operations.

Benefits

  • Enhanced flexibility: Customize cache behavior without modifying zone-level Cache Rules.
  • Dynamic optimization: Adjust caching strategies in real-time based on request context.
  • Simplified configuration: Reduce the number of Cache Rules needed by handling edge cases programmatically.
  • Improved performance: Fine-tune cache behavior for specific use cases to maximize hit rates.

Get started

To get started, refer to the Workers Fetch API documentation and the cf object properties documentation.

workerscacheapiperformanceedge

Source: original entry ↗

More from Cloudflare

Follow Cloudflare to get its new changes in your feed and email digest.

Improvement2026.8.2100.0

Cloudflare One Client for macOS 2026.8.2100.0

GA release for macOS Cloudflare One Client with improved split tunnel handling that no longer briefly blocks traffic during reconnects, support for non-RFC 1918 local IPv4 networks, faster connects with lower memory use, and numerous reliability fixes across DNS, reauthentication, and client stability.

macosvpnreliabilityperformancedns
Improvement2026.8.2100.0

Cloudflare One Client for Windows 2026.8.2100.0

This GA release improves split tunnel reliability, adds support for non-RFC 1918 local networks, optimizes connection performance with faster reconnections and lower memory usage, and includes numerous bug fixes for DNS, registration, and network handling. The client now features a service recovery mechanism that automatically restarts on system unlock and better handles large hosts files without blocking traffic.

windowsvpnclienttunneldns
Improvement2026.8.2100.0

Cloudflare One Client for Linux 2026.8.2100.0

New GA release for Linux with improved split tunnel handling that no longer briefly blocks traffic during reconnects, support for non-RFC 1918 local IPv4 networks, faster tunnel reconnections, and lower memory usage. Includes numerous stability and reliability fixes for DNS, reconnection behavior, and crash issues.

linuxvpnclientperformancestability
See all Cloudflare changes →