Ticket #12399: patch1.diff

File patch1.diff, 1.9 KB (added by houdinihound, 15 years ago)
  • django/contrib/sessions/backends/cached_db.py

     
    66from django.contrib.sessions.backends.db import SessionStore as DBStore
    77from django.core.cache import cache
    88
     9import time
     10
    911class SessionStore(DBStore):
    1012    """
    1113    Implements cached, database backed sessions.
     
    1820        data = cache.get(self.session_key, None)
    1921        if data is None:
    2022            data = super(SessionStore, self).load()
    21             cache.set(self.session_key, data, settings.SESSION_COOKIE_AGE)
     23            expires = settings.SESSION_COOKIE_AGE
     24            # Memcached needs a unix timestamp for expiry values greater than 2592000.
     25            if settings.CACHE_BACKEND.lower().startswith('memcached') and expires > 2592000:
     26                cache.set(self.session_key, data, int(time.time()) + settings.SESSION_COOKIE_AGE)
     27            else:
     28                cache.set(self.session_key, data, settings.SESSION_COOKIE_AGE)
    2229        return data
    2330
    2431    def exists(self, session_key):
     
    2633
    2734    def save(self, must_create=False):
    2835        super(SessionStore, self).save(must_create)
    29         cache.set(self.session_key, self._session, settings.SESSION_COOKIE_AGE)
     36        expires = settings.SESSION_COOKIE_AGE
     37        # Memcached needs a unix timestamp for expiry values greater than 2592000.
     38        if settings.CACHE_BACKEND.lower().startswith('memcached') and expires > 2592000:
     39            cache.set(self.session_key, self._session, int(time.time()) + settings.SESSION_COOKIE_AGE)
     40        else:       
     41            cache.set(self.session_key, self._session, settings.SESSION_COOKIE_AGE)
    3042
    3143    def delete(self, session_key=None):
    3244        super(SessionStore, self).delete(session_key)
Back to Top