~ubuntu-branches/ubuntu/quantal/python-django/quantal

« back to all changes in this revision

Viewing changes to django/contrib/sessions/backends/cached_db.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2009-07-29 11:26:28 UTC
  • mfrom: (1.1.8 upstream) (4.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090729112628-pg09ino8sz0sj21t
Tags: 1.1-1
* New upstream release.
* Merge from experimental:
  - Ship FastCGI initscript and /etc/default file in python-django's examples
    directory (Closes: #538863)
  - Drop "05_10539-sphinx06-compatibility.diff"; it has been applied
    upstream.
  - Bump Standards-Version to 3.8.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
Cached, database-backed sessions.
 
3
"""
 
4
 
 
5
from django.conf import settings
 
6
from django.contrib.sessions.backends.db import SessionStore as DBStore
 
7
from django.core.cache import cache
 
8
 
 
9
class SessionStore(DBStore):
 
10
    """
 
11
    Implements cached, database backed sessions.
 
12
    """
 
13
 
 
14
    def __init__(self, session_key=None):
 
15
        super(SessionStore, self).__init__(session_key)
 
16
 
 
17
    def load(self):
 
18
        data = cache.get(self.session_key, None)
 
19
        if data is None:
 
20
            data = super(SessionStore, self).load()
 
21
            cache.set(self.session_key, data, settings.SESSION_COOKIE_AGE)
 
22
        return data
 
23
 
 
24
    def exists(self, session_key):
 
25
        return super(SessionStore, self).exists(session_key)
 
26
 
 
27
    def save(self, must_create=False):
 
28
        super(SessionStore, self).save(must_create)
 
29
        cache.set(self.session_key, self._session, settings.SESSION_COOKIE_AGE)
 
30
 
 
31
    def delete(self, session_key=None):
 
32
        super(SessionStore, self).delete(session_key)
 
33
        cache.delete(session_key or self.session_key)
 
34
 
 
35
    def flush(self):
 
36
        """
 
37
        Removes the current session data from the database and regenerates the
 
38
        key.
 
39
        """
 
40
        self.clear()
 
41
        self.delete(self.session_key)
 
42
        self.create()
 
 
b'\\ No newline at end of file'