Repository navigation
feat(cache)!: sort query parameters in HTTP cache keys by default - #409
Merged
Merged
Conversation
sort_query now defaults to sorting in @cache, invalidate(), build_cache_key() and CacheKey.from_request(), so ?b=2&a=1 and ?a=1&b=2 share one entry. The sort is stable: repeated values of one name keep the order sent. sort_query=False keeps the query as sent. @cache and invalidate() take sort_query=None to mean "not passed". Any explicit value together with a custom key_builder raises CacheXError, False included: build_cache_key() in the builder sorts by default, so the flag would silently not do what it says. BREAKING CHANGE: query parameters are sorted in HTTP cache keys by default. A handler that depends on the query order as sent must set @cache(sort_query=False) and pass the same to invalidate(). sort_query passed with a custom key_builder is rejected, False included. Closes #72
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #72. Last of the 0.4.0 cache key changes (#405–#408).
What changes
sort_querynow defaults to sorting in@cache,invalidate(),build_cache_key()andCacheKey.from_request(), so?b=2&a=1and?a=1&b=2share one entry.sort_query=Falseis the opt-out, for handlers whose response depends on the query order as sent. Pass the same value toinvalidate().@cacheandinvalidate()takesort_query: bool | None = None;Nonemeans "not passed".sort_querytogether with a customkey_builderraisesCacheXError,Falseincluded.build_cache_key()inside the builder sorts by default, sokey_builder=b, sort_query=Falsewould silently not do what it says.Falsethere, where it had no effect, and did not warn. The error is raised when the decorator is applied, not at request time.MIGRATING_0_4.mdcovers this.Docs
HTTP_CACHING,CACHE_FLOWandMIGRATING_0_4are updated in English and zh-TW.HTTP_CACHINGexample now shows when to usesort_query=False.changelog.d/72.changed.md.Tests
default_key_buildertests now use a realRequest.Trueboth merge reordered queries;Falsekeeps reordered queries apart;key_builder, in@cacheand ininvalidate();invalidate()andsort_query=Falseround-trip;Falsethrough with akey_builder;Falseto the default builder.