Use Cached Sessions
A snippet showing how to use cached sessions in Django.
# settings.py
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "default" # pick from CACHES
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.memcached.MemcachedCache",
"LOCATION": "127.0.0.1:11211",
}
}
Explanation:
- Session data is stored in fast cache storage for quicker reads/writes.
- Greatly improves performance when you need to store session data.
- Category Performance & Optimization
- Total Views 968
- Last Modified 19 April, 2026
- Tags #performance #sessions #caching #optimization
Previous snippet
Optimize QuerySets with exists()
Next snippet