docs(http-cache): align HTTP caching docs and docstrings with the code - #361
Merged
Merged
Conversation
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.
Docs/docstring accuracy audit of the HTTP caching area. Documentation, docstrings and comments only; no runtime change (AST check: docstring/comment-only).
Corrections
docs/CACHE_FLOW.md (and zh-TW mirror)
no-storecheck. It is built only after every bypass check, right before the backend read, so the key builder never runs forno-storeor bypassed requests. The diagram now shows the key built at that point, with thevarycomponents.ttl(ttl=None/0), which skip the backend exactly likeprivate=True. Added. "Cached entry exists, ttl is set" is now "Cached entry exists" (ttl is always positive by then). The diagram also mentionsfail_openon read/write andVaryon GET responses.Authorization. It now showsrequest_credential(Authorization, a session the middleware loaded, non-emptyrequest.session), that it is skipped when the route already bypasses, and where the key is built.sort_query=Truedoes this now.no_cache=Truestores entries only with a positivettl. The list of decoration-timeCacheXErrors now includes the missing cases:ttltype/range,vary,sort_query, and an asynckey_builder.CacheEntrylisting was missing thestored_atfield.Agewas missing from the headers that are never stored.docs/HTTP_CACHING.md (and zh-TW mirror)
varyhad one|too many between the empty query and the next component. The real keys are.../greeting||||||tenant-1|||...and.../me||||||authorization=....private=True, no positivettl) do not check for credentials. TheirCache-Controlis sent unchanged, with noprivateadded.CacheManager, session, state and lock keys are skipped.fastapi_cachex/cache.py
cache()docstring,cache_authorized: added the same qualification about routes that skip the backend anyway.If-None-Match. It also runs when the header did not match.fastapi_cachex/routes.py
Possible code issues (not changed)
fastapi_cachex/cache.py:1178/1224-1228: the credential check is skipped wheneverbypass_backendis true. On attl=0route withmust_revalidate=True, anAuthorizationrequest is answeredCache-Control: max-age=0, must-revalidate, withoutprivate. RFC 9111 §3.5 lets a shared cache store that response. On positive-ttl routes the library deliberately addsprivatein this case.fastapi_cachex/cache.py:1145/_with_cache_control: a plain@cache()(no ttl or other directives) sends an emptyCache-Control:header, because_build_cache_controlreturns""and it is set unconditionally.