Skip to content

Commit

Permalink
Optimized the cached_db session backend to check if a key exists in t…
Browse files Browse the repository at this point in the history
…he cache first.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17156 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
aaugustin committed Nov 27, 2011
1 parent bda21e2 commit c11f9c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions django/contrib/sessions/backends/cached_db.py
Expand Up @@ -28,6 +28,8 @@ def load(self):
return data return data


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


def save(self, must_create=False): def save(self, must_create=False):
Expand Down
5 changes: 5 additions & 0 deletions django/contrib/sessions/tests.py
Expand Up @@ -293,6 +293,11 @@ class CacheDBSessionTests(SessionTestsMixin, TestCase):


backend = CacheDBSession 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) CacheDBSessionWithTimeZoneTests = override_settings(USE_TZ=True)(CacheDBSessionTests)


Expand Down

0 comments on commit c11f9c3

Please sign in to comment.