Skip to content

@cache: opt-in sort_query to merge reordered query strings #267

Description

@allen0099

Problem

The query string goes into the key in the order the client sent it, so ?a=1&b=2 and ?b=2&a=1 are two cache entries. This is documented, and the workaround is a custom key_builder. But it is a common need, and hand-written key builders are error-prone (see #230).

Proposal

Add an opt-in @cache(sort_query=True) that sorts the query parameters by name before building the key.

  • Keep the original order of repeated values for the same name: ?tag=b&tag=a must stay distinct from ?tag=a&tag=b, since many apps treat that order as meaningful.
  • Default stays False, so existing keys and semantics are unchanged.

Activity

  1. added this to the 0.3.9 milestone on Sep 26, 2026
  2. added
    enhancementNew feature or request
    http-cacheThe @cache decorator, cache keys and Cache-Control handling
    on Sep 26, 2026
  3. allen0099 commented on Sep 27, 2026

    @allen0099
    OwnerAuthor

    A first-time user hit this too: ?limit=1&q=wid and ?q=wid&limit=1 were cached as separate entries. The docs do mention it, but only an opt-in makes the fix easy to find.

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