Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Optimized the cached_db session backend to check if a key exists in t…

…he cache first.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17156 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c11f9c3193901215ec79732af6ab6c66b3c1c2ba 1 parent bda21e2
Aymeric Augustin authored November 27, 2011
2  django/contrib/sessions/backends/cached_db.py
@@ -28,6 +28,8 @@ def load(self):
28 28
         return data
29 29
 
30 30
     def exists(self, session_key):
  31
+        if (KEY_PREFIX + session_key) in cache:
  32
+            return True
31 33
         return super(SessionStore, self).exists(session_key)
32 34
 
33 35
     def save(self, must_create=False):
5  django/contrib/sessions/tests.py
@@ -293,6 +293,11 @@ class CacheDBSessionTests(SessionTestsMixin, TestCase):
293 293
 
294 294
     backend = CacheDBSession
295 295
 
  296
+    def test_exists_searches_cache_first(self):
  297
+        self.session.save()
  298
+        with self.assertNumQueries(0):
  299
+            self.assertTrue(self.session.exists(self.session.session_key))
  300
+
296 301
 
297 302
 CacheDBSessionWithTimeZoneTests = override_settings(USE_TZ=True)(CacheDBSessionTests)
298 303
 

0 notes on commit c11f9c3

Please sign in to comment.
Something went wrong with that request. Please try again.