Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

Efficiently clear expired sessions from the database.

Project description

By default, Django’s cached_db and db session backends loop through deleted sessions in order to trigger pre/post delete signal handlers. This can be extremely slow and consume a lot of CPU and memory on sites with a lot of sessions.

This package provides a SessionStoreMixin class and alternative cached_db and db backends that use the private _raw_delete() method, which is much faster and consumes much less CPU and memory, but does not trigger pre/post delete signal handlers.

Usage

Add to your settings:

SESSION_ENGINE = 'django_raw_clearsessions.cached_db'

Or:

SESSION_ENGINE = 'django_raw_clearsessions.db'

Or:

# mybackend.py
from some.package import some_backend
from django_raw_clearsessions import SessionStoreMixin


class SessionStore(SessionStoreMixin, some_backend.SessionStore):
    pass

# settings.py
SESSION_ENGINE = 'mybackend'

Execute the Django clearsessions management command:

$ python manage.py clearsessions

Project details


Release history Release notifications

This version
History Node

0.1

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
django_raw_clearsessions-0.1-py2.py3-none-any.whl (2.8 kB) Copy SHA256 hash SHA256 Wheel 2.7

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page