django-cacheops
A slick ORM cache with automatic granular event-driven invalidation for Django.
What it is and what it does
django-cacheops is a Django caching layer that sits between your ORM and Redis to automatically cache querysets and invalidate them when underlying data changes. It supports both automatic caching (configured per-model) and manual caching via `.cache()` method calls, plus decorators for caching function results. The package uses Redis as its primary backend and can fall back to filesystem-based time-invalidated caching for simpler use cases.
The core value is granular, event-driven invalidation: when you save, delete, or update a model instance, cacheops automatically invalidates only the relevant cached queries rather than flushing everything. It also provides decorators to cache any user function or view, template extensions for Django and Jinja2, transparent transaction support, and a dog-pile prevention mechanism to avoid thundering-herd problems when cache entries expire.
Use it for:
- Cache frequently accessed User.objects.get() calls across a Django app to reduce database load on auth queries.
- Automatically invalidate cached article listings when posts are published, updated, or deleted without manual cache management.
- Decorate expensive reporting functions with @cached_as(Model) to cache results and invalidate them on model changes.
- Use .nocache() to disable automatic caching on specific querysets when you need fresh data in particular code paths.
- Cache count and aggregate operations on large tables separately from fetch operations to optimize pagination.
- Configure per-model cache timeouts and operations (get, fetch, count, aggregate, exists) to fine-tune what gets cached.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Automatic and manual ORM query caching for Django with Redis-backed storage and granular event-driven cache invalidation tied to model changes.
Yes. django-cacheops is actively maintained, has no known vulnerabilities, low install friction, and solves a real Django performance problem with a mature API. The permissive BSD license and broad Python/Django version support (3.8+ and Django 3.2–5.2) make it a safe choice. Install it if you have a Django app with database-heavy ORM queries and a Redis instance available; the automatic invalidation model eliminates much of the complexity of manual cache management.
Install
django-cacheops on PyPI
pip
pip install django-cacheopsuv
uv add django-cacheopspoetry
poetry add django-cacheopsInstalling django-cacheops
Before you install
Low install friction; wheel distribution available. Actively maintained with recent commits and stable production status. Requires Redis 4.0+ as a runtime dependency alongside Django 3.2+ and Python 3.8+.
License in practice
BSD permissive license allows commercial and private use with minimal restrictions; suitable for most projects.
Quickstart
pip install django-cacheops
# In Django settings.py:
INSTALLED_APPS = ['cacheops', ...]
CACHEOPS_REDIS = 'redis://localhost:6379/1'
CACHEOPS = {'auth.user': {'ops': 'get', 'timeout': 60*15}}
# In code:
from cacheops import cached_as
user = User.objects.get(id=1) # cached automatically
result = Article.objects.filter(tag=2).cache()
Redis 4.0+ server must be running and accessible; Django 3.2+ and Python 3.8+ required.
Verify before relying
- Whether dog-pile prevention mechanism and transaction support work as documented in production scenarios.
- Performance impact of signal binding overhead on models with high write volume.
- Compatibility with Django ORM features introduced after version 5.2.
Package facts
| License | BSD (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — django, redis, funcy |
| Maintenance | actively maintained — 481 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,321,573/month — #4,062 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_cacheops-7.2-py2.py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
django-cachalotAutomatically caches Django ORM queries and…
permissive · top 15,000 on PyPI
django-redisProvides a Redis cache and session backend for…
permissive · top 5,000 on PyPI
django-sql-utilsProvides simplified APIs for Django querysets…
permissive · top 15,000 on PyPI
django-cache-memoizeA decorator that caches function results using…
copyleft · top 15,000 on PyPI
django-mock-queriesMocks Django QuerySet operations in memory for…
permissive · top 15,000 on PyPI
python-redis-cacheDecorator-based caching for Python functions…
permissive · top 15,000 on PyPI
django-cache-urlConfigures Django cache backends from…
permissive · top 15,000 on PyPI
django-redis-sessionsProvides a Redis-backed session storage backend…
permissive · top 15,000 on PyPI
CollectfastCollectfast accelerates Django's collectstatic…
permissive · top 15,000 on PyPI
django-perf-recRecords and compares Django database queries…
permissive · top 15,000 on PyPI