app/django/contrib/sessions/backends/cache.py
author Todd Larsen <tlarsen@google.com>
Tue, 26 Aug 2008 21:20:44 +0000
changeset 103 094c8f741a08
parent 54 03e267d67478
child 323 ff1a9aa48cfd
permissions -rw-r--r--
Move LICENSE.django closer to the actual trumk/app/django code we are importing (that exists in trunk/app to be part of the Google App Engine image). LICENSE.django cannot go in trunk/app/django itself, because that directory is maintained from the /vendor/django svn external using svn_load_dirs.pl (so putting all the way into trunk/app/django gets it repeatedly removed). Patch by: Todd Larsen Review by: to-be-reviewed

from django.conf import settings
from django.contrib.sessions.backends.base import SessionBase
from django.core.cache import cache

class SessionStore(SessionBase):
    """
    A cache-based session store. 
    """
    def __init__(self, session_key=None):
        self._cache = cache
        super(SessionStore, self).__init__(session_key)
        
    def load(self):
        session_data = self._cache.get(self.session_key)
        return session_data or {}

    def save(self):
        self._cache.set(self.session_key, self._session, settings.SESSION_COOKIE_AGE)

    def exists(self, session_key):
        if self._cache.get(session_key):
            return True
        return False
        
    def delete(self, session_key):
        self._cache.delete(session_key)