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

File details

Details for the file django-cached_authentication_middleware-0.1.0.tar.gz.

File metadata

File hashes

Hashes for django-cached_authentication_middleware-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7eacad5b411dd9c5141f0f043a5f9838e3b110055ed17d37d380e763e0c7609d
MD5 3a5a8653d016b71609b6d82952ecd0e3
BLAKE2b-256 325ed49b0cb3ab49b6fc228649a8f3d0bcb38623b723c508355e3f45d406854d

See more details on using hashes here.

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