Ticket #18194: files-sessions-server-expiry-1.patch

File files-sessions-server-expiry-1.patch, 1.1 KB (added by Rohan Jain, 13 years ago)

Patch 1 - Use OS file info to expire sessions

  • django/contrib/sessions/backends/file.py

    diff --git a/django/contrib/sessions/backends/file.py b/django/contrib/sessions/backends/file.py
    index cb81534..024a193 100644
    a b  
    11import errno
    22import os
    33import tempfile
     4import time
    45
    56from django.conf import settings
    67from django.contrib.sessions.backends.base import SessionBase, CreateError
    class SessionStore(SessionBase):  
    5051            session_file = open(self._key_to_file(), "rb")
    5152            try:
    5253                file_data = session_file.read()
     54                # The age of session file from last modify time
     55                age = time.time() - os.path.getmtime(self._key_to_file())
     56                expired = age > settings.SESSION_COOKIE_AGE
    5357                # Don't fail if there is no data in the session file.
    5458                # We may have opened the empty placeholder file.
    55                 if file_data:
     59                if not expired and file_data:
    5660                    try:
    5761                        session_data = self.decode(file_data)
    5862                    except (EOFError, SuspiciousOperation):
Back to Top