django-cachalot is a Django package that automatically caches all Django ORM queries and transparently invalidates them when data changes. It aims to provide significant performance improvements by reducing database hits without requiring developers to write explicit caching logic. The library is actively maintained, with version 2.9.0 supporting recent Django releases and Python versions, and new releases frequently adapting to Django's evolution.
pip install django-cachalotVerified import paths — ran on the pinned version, not inferred.
To enable django-cachalot, add 'cachalot' to your `INSTALLED_APPS` and ensure you have a Django cache backend configured in your `CACHES` setting. For production, a shared cache like Redis or Memcached is recommended. For local development, `LocMemCache` can be used, but be aware of its limitations in multi-process environments. It's often beneficial to configure `IGNORE_EXCEPTIONS` for your cache backend to prevent application crashes if the cache service is unavailable.
Upgrade your Django project to a compatible version or use an older django-cachalot release that supports your Django version.
Upgrade your Django project to a compatible version or use an older django-cachalot release.
Evaluate if django-cachalot's per-table invalidation strategy aligns with your application's write patterns. For very high-write tables, consider alternative caching strategies (e.g., per-object caching with other libraries like `django-cacheops` or `django-cache-machine` for hot data, or manual caching for specific querysets) or optimize database queries directly.
If caching is critical for raw SQL queries, implement manual caching for those specific cases using Django's low-level cache API. Ensure that manual invalidation is handled correctly when underlying data changes.
For multi-process deployments, use a shared cache backend like Redis (`django-redis`) or Memcached.
After modifying `CACHALOT_CACHE`, run `./manage.py invalidate_cachalot` to clear the cache, or manually clear the old cache alias using its specific API if you need to retain other cache data.
Upgrade to django-cachalot v2.9.0 or later to benefit from the fix for atomic transaction recursion issues.