Skip to content
Cloudflare Blog·

Cloudflare Adds Vary Support to Cache Rules

Cloudflare's Vary in Cache Rules is a game-changer for negotiated content

TL;DR

Cloudflare now supports Vary in Cache Rules, allowing developers to manage cache behavior for negotiated content more effectively. This feature helps prevent serving the wrong response to clients and optimizes cache performance for headers with high cardinality.

Cloudflare has introduced support for the Vary header in its Cache Rules, enabling developers to better manage cache behavior for negotiated content. This means that when a server returns a response with a Vary header, Cloudflare can now handle it according to specific rules, rather than treating it as a cache bypass. This is crucial for developers who need to serve different content based on client preferences, such as language or format, without losing cache efficiency. The new feature offers three actions for handling Vary headers: normalize, passthrough, and bypass, with normalize being the default. This allows for fine-grained control over how cache keys are generated, ensuring that the cache can serve the correct response to each client.

Cloudflare Adds Vary Support to Cache Rules — Cloudflare Blog

Key Points

1

Cloudflare's Cache Rules now support Vary headers, enabling three actions: normalize, passthrough, and bypass.

2

Normalize is the default action, ensuring cache keys are generated based on controlled sets of values.

3

Passthrough preserves the exact value of the header for cache matching, useful for headers with specific response changes.

4

Bypass prevents caching when the origin names a header in Vary, ideal for headers with unique or personal values.

5

Cloudflare customers can now manage cache behavior for negotiated content more effectively, improving performance and correctness.

Why It Matters

If you're dealing with high-cardinality headers like User-Agent or Accept, Cloudflare's new Vary support in Cache Rules can significantly improve cache performance and correctness. For instance, using normalize for headers with controlled sets of values ensures cache efficiency, while bypassing caching for unique or personal values prevents incorrect responses. This is especially useful for APIs serving different content based on client preferences.

cloudflarecache-rulesvary-headerhigh-cardinalitynegotiated-content

Comments

Subscribe to join the conversation...

Be the first to comment

Enjoyed this article?

Get it daily. 7am. Free. Reads in 5 minutes.

Join 3,491 builders reading daily.

Also get