Memcached Sessions in Django
April 28, 2010
I needed non-database sessions in a Django app. This can be achieved using memcached on a server, and then configuring Django to store session information in it.
Memcached
On a fedora box installing memcached itself was as simple as:
yum install memcached
Django settings.py
CACHE_BACKEND = 'memcached://server:11211/' SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
Django code
To put objects in the session:
request.session['SessionKey'] = lObject
To get objects out of the session:
lObject = request.session['SessionKey']