diff --git a/django/contrib/sessions/backends/base.py b/django/contrib/sessions/backends/base.py index f64ef852cfb..b553fa4d58c 100644 --- a/django/contrib/sessions/backends/base.py +++ b/django/contrib/sessions/backends/base.py @@ -121,7 +121,11 @@ class SessionBase(object): return self._session.iteritems() def clear(self): - self._session.clear() + # To avoid unnecessary persistent storage accesses, we set up the + # internals directly (loading data wastes time, since we are going to + # set it to an empty dict anyway). + self._session_cache = {} + self.accessed = True self.modified = True def _get_new_session_key(self): diff --git a/django/contrib/sessions/backends/cache.py b/django/contrib/sessions/backends/cache.py index 157d18a586f..dad5117ea30 100644 --- a/django/contrib/sessions/backends/cache.py +++ b/django/contrib/sessions/backends/cache.py @@ -42,6 +42,8 @@ class SessionStore(SessionBase): def delete(self, session_key=None): if session_key is None: + if self._session_key is None: + return session_key = self._session_key self._cache.delete(session_key) diff --git a/django/contrib/sessions/backends/db.py b/django/contrib/sessions/backends/db.py index e697bc56b12..0d68f13e68b 100644 --- a/django/contrib/sessions/backends/db.py +++ b/django/contrib/sessions/backends/db.py @@ -63,6 +63,8 @@ class SessionStore(SessionBase): def delete(self, session_key=None): if session_key is None: + if self._session_key is None: + return session_key = self._session_key try: Session.objects.get(session_key=session_key).delete() diff --git a/django/contrib/sessions/backends/file.py b/django/contrib/sessions/backends/file.py index 3438b097c4e..1540139710d 100644 --- a/django/contrib/sessions/backends/file.py +++ b/django/contrib/sessions/backends/file.py @@ -94,6 +94,8 @@ class SessionStore(SessionBase): def delete(self, session_key=None): if session_key is None: + if self._session_key is None: + return session_key = self._session_key try: os.unlink(self._key_to_file(session_key))