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:
- Setting custom cache options: Pass cache properties in the
cfobject as the second argument tofetch()to override default Cache Rules. - Dynamic cache control: Apply different caching strategies based on request headers, cookies, or other runtime conditions.
- Per-request customization: Bypass or modify Cache Rules for individual requests while maintaining default behavior for others.
- 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.
Source: Cloudflare
Latest Posts
- Microsoft Entra ID: General Availability of passkey profiles and migration for existing Passkeys (FIDO2) tenants [MC1221452]
![Microsoft Entra ID: General Availability of passkey profiles and migration for existing Passkeys (FIDO2) tenants [MC1221452] 2 pexels zachtheshoota 1888883](data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==)
- (Updated) Microsoft Loop – User Accessible Recycle Bin for Loop workspaces [MC929021]
![(Updated) Microsoft Loop – User Accessible Recycle Bin for Loop workspaces [MC929021] 3 pexels elina araja 1743227 3377405](data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==)
- (Updated) New features coming to Microsoft 365 Copilot Chat for Outlook, Word, Excel, and PowerPoint [MC1187671]
![(Updated) New features coming to Microsoft 365 Copilot Chat for Outlook, Word, Excel, and PowerPoint [MC1187671] 4 pexels onewayupdesigns 2085831](data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==)
- (Updated) Microsoft 365 Copilot: Updates to PowerPoint on‑canvas features with Agent mode [MC1243550]
![(Updated) Microsoft 365 Copilot: Updates to PowerPoint on‑canvas features with Agent mode [MC1243550] 5 pexels tim samuel 5838215](data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==)

![Microsoft Entra ID: General Availability of passkey profiles and migration for existing Passkeys (FIDO2) tenants [MC1221452] 2 pexels zachtheshoota 1888883](https://mwpro.co.uk/wp-content/uploads/2024/08/pexels-zachtheshoota-1888883-150x150.webp)
![(Updated) Microsoft Loop – User Accessible Recycle Bin for Loop workspaces [MC929021] 3 pexels elina araja 1743227 3377405](https://mwpro.co.uk/wp-content/uploads/2024/08/pexels-elina-araja-1743227-3377405-150x150.webp)
![(Updated) New features coming to Microsoft 365 Copilot Chat for Outlook, Word, Excel, and PowerPoint [MC1187671] 4 pexels onewayupdesigns 2085831](https://mwpro.co.uk/wp-content/uploads/2024/08/pexels-onewayupdesigns-2085831-150x150.webp)
![(Updated) Microsoft 365 Copilot: Updates to PowerPoint on‑canvas features with Agent mode [MC1243550] 5 pexels tim samuel 5838215](https://mwpro.co.uk/wp-content/uploads/2025/06/pexels-tim-samuel-5838215-150x150.webp)
