Skip to content

Warn when the MemoryBackend fallback is registered implicitly (per-process cache under multiple workers) #327

Description

@allen0099

Problem

When no backend is configured, @cache / AppCache register a MemoryBackend silently (get_backend_or_fallback). Under uvicorn --workers N or gunicorn, each process then has its own cache. An invalidation from a write reaches one worker, and the other workers keep serving the old value until it expires:

PUT /products/1 -> price 1.0
GET /products/1 -> alternates between 1.0 and 9.99 across workers

BACKENDS.md mentions this once; at runtime the fallback is logged only at DEBUG.

Proposal

Log a WARNING (once per process) when the memory fallback is registered implicitly. It should say that the cache is per process and name BackendProxy.set(...). An explicit BackendProxy.set(MemoryBackend()) stays silent.

Activity

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

    backendsCache backends and their atomic primitivesdeveloper-experienceSurprising behaviour, missing warnings or unclear errors for library usersenhancementNew feature or request

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions