Cache Key

What Is a Cache Key?

A cache key is the identifier a caching system uses to look up a stored response. It connects an incoming request to content that might already be available, such as an image, video segment, or API response.

The key is constructed from selected request information. Depending on the caching system, this can include the URL, query parameters, headers, cookies, or other configured values. Different cache layers can use different rules, so a cache key is not universally identical to the visible URL.

For media delivery, these rules determine which requests can share an image or video representation and which need separate entries.

How a Cache Key Works

When a request arrives, the cache applies its matching rules and looks for a corresponding stored response.

A matching key does not automatically mean the response can be served immediately. The cache must also respect freshness, validation, and other reuse requirements. If no suitable response is available, it may retrieve content from an upstream cache or origin server.

HTTP caching uses the request method and target URI as foundational matching information. The Vary response header can identify additional request headers that affect response selection.

Distinguishing Media Variants

Consider a diagram delivered at two widths:

Request Intended representation
/media/diagram.png?width=320 Small preview
/media/diagram.png?width=1280 Larger display image

If the origin uses width to generate different images, the cache must preserve that distinction. Ignoring the parameter could cause a request for the larger image to receive the smaller version.

The distinction can also come from headers. If an endpoint selects an image format using the request’s Accept header, matching must account for that selection through supported variation rules. A common HTTP mechanism is Vary: Accept.

What Should a Cache Key Include?

A useful key distinguishes requests that require different responses while allowing equivalent requests to reuse content.

For media, relevant inputs might include the asset path, version, dimensions, crop, quality, or output format. Their location depends on the delivery URL and transformation system.

Other request values may be irrelevant to the response. A parameter used solely for analytics might be excluded after confirming that it does not affect the content or other response properties.

Some CDNs support including selected query parameters and headers in custom keys. Normalization can also consolidate equivalent request forms, but its rules must remain consistent with how the origin interprets requests.

Cache Key vs. Cache-Control and ETag

These concepts have separate roles:

Concept Role
Cache key Identifies a candidate stored response
Cache-Control Sets rules governing storage and reuse
ETag Provides a validator for checking a representation

Changing a key changes which entry a request addresses. It does not, by itself, establish how long that entry remains fresh or prove that its content is current.

Why Cache Keys Matter

A media library may serve many versions of the same source asset. Effective matching lets repeated requests reuse the correct version instead of repeatedly fetching or generating it.

Unnecessary distinctions work against that goal. If equivalent requests generate separate keys, each entry receives fewer opportunities for reuse. This fragmentation can increase origin work and cache storage requirements.

Correctness matters alongside hit ratio. Reusing the wrong crop, language, or format is not an improvement, even if it produces more cache hits.

QUICK TIPS
Jen Looper
Cloudinary Logo

Here are some tips to better understand cache key:

  1. List response-changing inputs
    Identify transformation, format, language, and access-related differences before changing matching rules.
  2. Exclude parameters selectively
    Confirm their effect before ignoring an entire query string.
  3. Normalize only equivalent requests
    Check that the origin interprets consolidated forms identically.
  4. Test both sharing and separation
    Verify that equivalent requests reuse content and different variants remain distinct.
  5. Test invalidation after customization
    Confirm that purge operations reach every intended variant.
Last updated: Dec 2, 2026
★★★★★
4.6 (23 reviews)
Talk to Sales Talk to Sales