2007-09-16 05:29:14 +08:00
|
|
|
from django.conf import settings
|
|
|
|
from django.contrib.sessions.backends.base import SessionBase
|
|
|
|
from django.core.cache import cache
|
|
|
|
|
|
|
|
class SessionStore(SessionBase):
|
|
|
|
"""
|
2008-06-08 04:28:06 +08:00
|
|
|
A cache-based session store.
|
2007-09-16 05:29:14 +08:00
|
|
|
"""
|
|
|
|
def __init__(self, session_key=None):
|
|
|
|
self._cache = cache
|
|
|
|
super(SessionStore, self).__init__(session_key)
|
2008-06-08 04:28:06 +08:00
|
|
|
|
2007-09-16 05:29:14 +08:00
|
|
|
def load(self):
|
|
|
|
session_data = self._cache.get(self.session_key)
|
|
|
|
return session_data or {}
|
|
|
|
|
|
|
|
def save(self):
|
2008-06-08 04:28:06 +08:00
|
|
|
self._cache.set(self.session_key, self._session, self.get_expiry_age())
|
2007-09-16 05:29:14 +08:00
|
|
|
|
|
|
|
def exists(self, session_key):
|
|
|
|
if self._cache.get(session_key):
|
|
|
|
return True
|
|
|
|
return False
|
2008-06-08 04:28:06 +08:00
|
|
|
|
2007-09-16 05:29:14 +08:00
|
|
|
def delete(self, session_key):
|
|
|
|
self._cache.delete(session_key)
|