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.
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.