Commit c11f9c31 authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

Optimized the cached_db session backend to check if a key exists in the cache first.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@17156 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent bda21e2b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ class SessionStore(DBStore):
        return data

    def exists(self, session_key):
        if (KEY_PREFIX + session_key) in cache:
            return True
        return super(SessionStore, self).exists(session_key)

    def save(self, must_create=False):
+5 −0
Original line number Diff line number Diff line
@@ -293,6 +293,11 @@ class CacheDBSessionTests(SessionTestsMixin, TestCase):

    backend = CacheDBSession

    def test_exists_searches_cache_first(self):
        self.session.save()
        with self.assertNumQueries(0):
            self.assertTrue(self.session.exists(self.session.session_key))


CacheDBSessionWithTimeZoneTests = override_settings(USE_TZ=True)(CacheDBSessionTests)