Skip to content

@cache: vary= to key responses on selected request headers #268

Description

@allen0099

Problem

The key does not include any request header. A route whose response depends on Accept-Language, Accept or Accept-Encoding serves whichever variant was cached first to every client. Setting Vary on the response tells downstream caches, but not our own backend.

Proposal

Add @cache(vary=["Accept-Language"]):

  • Append each listed header's value (normalised: lower-cased name, trimmed value, missing as empty) to the key, encoded with escape_key_component.
  • Add the same names to the response's Vary header.
  • Header values are client-controlled, so document that each listed header multiplies the number of entries. Consider an optional allow-list or normaliser per header, e.g. to reduce Accept-Language to a supported locale.

Additive; routes without vary keep their keys.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthttp-cacheThe @cache decorator, cache keys and Cache-Control handling

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions