diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2011-11-27 18:36:03 +0000 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2011-11-27 18:36:03 +0000 |
| commit | c11f9c3193901215ec79732af6ab6c66b3c1c2ba (patch) | |
| tree | dba83362f1d7fc9701a1eeb97b62bb956fe52878 | |
| parent | bda21e2b9d19f435d841a5ff9f8f636ae843842d (diff) | |
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
| -rw-r--r-- | django/contrib/sessions/backends/cached_db.py | 2 | ||||
| -rw-r--r-- | django/contrib/sessions/tests.py | 5 |
2 files changed, 7 insertions, 0 deletions
diff --git a/django/contrib/sessions/backends/cached_db.py b/django/contrib/sessions/backends/cached_db.py index 580e907c30..342aa600d3 100644 --- a/django/contrib/sessions/backends/cached_db.py +++ b/django/contrib/sessions/backends/cached_db.py @@ -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): diff --git a/django/contrib/sessions/tests.py b/django/contrib/sessions/tests.py index f94753cbcf..50297dce2f 100644 --- a/django/contrib/sessions/tests.py +++ b/django/contrib/sessions/tests.py @@ -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) |
