Skip to main content

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.


Add to your settings:

SESSION_ENGINE = 'django_raw_clearsessions.cached_db'


SESSION_ENGINE = 'django_raw_clearsessions.db'


from some.package import some_backend
from django_raw_clearsessions import SessionStoreMixin

class SessionStore(SessionStoreMixin, some_backend.SessionStore):

SESSION_ENGINE = 'mybackend'

Execute the Django clearsessions management command:

$ python clearsessions

Project details

Release history Release notifications | RSS feed

This version


Download files

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

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page