Skip to main content

A drop in replacement for django's built in AuthenticationMiddleware that utilizes caching.

Project description

django-cached_authentication_middleware is a drop in replacement for django.contrib.auth’s built in AuthenticationMiddleware. It tries to populate request.user by fetching user data from cache before falling back to the database.

Installation

  • Install via pypi:

    pip install django-cached_authentication_middleware
  • Configure CACHES in django’s settings.py:

    CACHES = {
        'default': {
            'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
            'LOCATION': '127.0.0.1:11211',
            'TIMEOUT': 36000,
        }
    }
  • Replace django.contrib.auth.middleware.AuthenticationMiddleware with cached_auth.Middleware in settings.py:

    MIDDLEWARE_CLASSES = (
        'django.middleware.common.CommonMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        #'django.contrib.auth.middleware.AuthenticationMiddleware'
        'cached_auth.Middleware',
    )

And you’re done!

Running Tests

To run the test suite:

django-admin.py test cached_auth --settings=cached_auth.tests.settings --pythonpath=.

Changelog

Version 0.1

  • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page