skillfed

django-cacheops

A slick ORM cache with automatic granular event-driven invalidation for Django.

django-cacheops v7.2 1.3M downloads/30d#4,062 on PyPI2,274
Permissive license BSD Active released

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-cacheops

uv

uv add django-cacheops

poetry

poetry add django-cacheops

Installing 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

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentFramework :: DjangoFramework :: Django :: 3.2Framework :: Django :: 4.0Framework :: Django :: 4.1Framework :: Django :: 4.2Framework :: Django :: 5.0Framework :: Django :: 5.1Framework :: Django :: 5.2Intended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Internet :: WWW/HTTPTopic :: Software Development :: Libraries :: Python Modules

Tags

django orm cachingredis query cacheautomatic cache invalidationdjango queryset cachecache decorator djangoorm cache invalidationdjango performance optimization
django-ormredis-cachequery-optimization

More Python Modules packages