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.1

  • Fixed an error where middleware tries to call “get_profile” on AnonymousUser

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.1.tar.gz.

File metadata

File hashes

Hashes for django-cached_authentication_middleware-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cc01d37453d6b0ec3099c4de6563fa21987bc2e4ef1cac73fae738996f0f08d6
MD5 a0157c5e3700019d77f320f2f01394c5
BLAKE2b-256 9bb1aa0d1c577def1a07c302e5c40676f20881061fd7841e05c1ac636aea4c59

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