Repository navigation
fix(cache): send no empty Cache-Control, and warn when no_store overrides other arguments - #431
Merged
Merged
Conversation
…ng; document the private exception
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.
Fixes #363. Closes #328.
#363: bare
@cache()sent an emptyCache-ControlWith neither
ttlnor a directive,_build_cache_controlreturns""and the decorator set it anyway, replacing the handler's own header. Now:_cache_control_forfalls back to the handler's ownCache-Controlwhen the decorator has none, and_with_cache_control/_not_modifiedskip an empty value, on both the 200 and the 304.Authorizationor a session, still getsprivate, as on every route (unchanged from before; now documented).A bare
@cache()is therefore an ETag-only mode: ETag, 304 on a matchingIf-None-Match, the handler's ownCache-Control. It does not warn: it now does something useful, a new warning would fail downstream test suites that run with warnings as errors in a patch release, and the only silencer would be a filter.#328: arguments that contradict each other
no_store=Truecombined withttl,stale/stale_ttl,no_cache,public,private,immutableormust_revalidateemits aUserWarningat decoration time naming the overridden arguments (stacklevelpoints at the user's@cache(...)line). Warning rather than raising keeps this non-breaking for 0.4.x. Behaviour is unchanged:no-storeonly.Out of scope (could be follow-ups):
no_cache=Truesilently droppingpublic/ttl/stale/immutablefrom the header, andno_storewithkey_builder/cache_authorized/sort_query.Tests
tests/test_cache_arguments.py: bare@cache()with no handler header, with the handler's header (200 + 304), withvary, with a streaming response, with a cookie and withAuthorization; everyno_storecombination; combinations that must not warn.no_storewith other arguments now assert the warning withpytest.warns, or ignore it per test where a shared parametrized helper builds the combination.Docs (EN + zh-TW):
HTTP_CACHING.md,CACHE_FLOW.md, and thecache()docstring.An independent review agent read the change before this PR. It led to dropping the warning on a bare
@cache(), documenting the cookie/credentialprivateexception, and adding the missing test cases.