Skip to main content
Pick a backend in .env. Memory is fine while you’re developing; Redis is what you want once more than one process is serving requests.
.env
CACHE_URL defaults to REDIS_URL. When CACHE_BACKEND is unset, REDIS_URL selects redis. See automatic backends.

Caching function results

Results are keyed by the function’s arguments, so each distinct call gets its own entry.

Caching route responses

cache_response varies on the current user by default. On a genuinely public page pass vary_on_user=False, or every visitor stores a separate copy of an identical response.

Direct access

The memory backend is per-process. Under gunicorn --workers 4 each worker keeps its own cache, so hit rates look worse than they are and invalidation reaches one worker only. Use redis whenever you run more than one process.