Repository navigation
feat(proxy): warn when the MemoryBackend fallback is registered implicitly - #347
Merged
Merged
Conversation
…citly get_backend_or_fallback() now logs a WARNING from inside the get_or_create factory, so it fires once per registration (once per process unless the proxy is reset). An explicit BackendProxy.set(MemoryBackend()) stays silent.
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 #327
Summary
When
@cache,CacheBackendorAppCacheregisters aMemoryBackendbecause no backend was set,get_backend_or_fallback()now logs aWARNINGon thefastapi_cachex.proxylogger. Before this change it logged only atDEBUG:BackendProxy.get_or_createruns under its lock, so it fires only when the fallback is actually created. Concurrent first callers on worker threads produce a single warning. If the proxy is reset withBackendProxy.set(None)(only tests do this), the next fallback is a new registration and warns again. That is intended.BackendProxy.set(MemoryBackend())never runs the factory, so it does not warn.logging, notwarnings, so it doesn't interact with warning filters.Docs
docs/BACKENDS.md"In-memory (default)": describes the warning and how to silence it by setting the backend explicitly.docs/HTTP_CACHING.mdanddocs/CACHE_FLOW.md: the fallback descriptions now mention the warning.changelog.d/327.changed.md.Tests
tests/test_fallback_warning.pyusescaplogto check that:@cache,AppCacheandCacheBackendwarns exactly once over repeated requests and direct calls;get_app_cacheandget_backend_or_fallback) warn once;BackendProxy.set(and says the cache is per process;BackendProxy.set(MemoryBackend())does not warn on any of the three paths.Mutation checks:
get_backend_or_fallbackfails the once tests and the explicit-backend tests.