RefreshSessionMiddleware

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
from django.conf import settings

REFRESH_AGE = getattr(settings, 'SESSION_COOKIE_REFRESH_AGE',
        int(settings.SESSION_COOKIE_AGE / 2))

class RefreshSessionMiddleware(object):
    """
    This middleware automatically refreshes the session after some time
    (default: settings.SESSION_COOKIE_AGE / 2).
    """
    def process_request(self, request):
        assert hasattr(request, 'session'), "RefreshSessionMiddleware " \
                "requires session middleware to be installed. Edit your " \
                "MIDDLEWARE_CLASSES setting to insert " \
                "'django.contrib.sessions.middleware.SessionMiddleware'."
        if request.session.get_expiry_age() < REFRESH_AGE:
            request.session.modified = True
        return None

More like this

  1. Sessions and authentication without cookies by danfairs 5 years, 6 months ago
  2. Effective content caching for mass-load site using redirect feature by nnseva 1 year, 10 months ago
  3. Remember me for login by iElectric 3 years, 4 months ago
  4. CurrentSessionIDMiddleware by troolee 2 years, 10 months ago
  5. MintCache by gfranxman 6 years, 1 month ago

Comments

robharvey (on October 25, 2008):

I think you'd want to ensure get_expiry_age() is >= 0 as well.

#

(Forgotten your password?)