Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Django Cache Magic

Project Description


Cache magic addresses two common scenarios for caching and cache invalidation
for django models: *instance caching* and *related objects caching*.

Instance caching: Storing instances of objects in your cache layer
as well as your database.

Related objects caching: Storing a collection of objects related to another
object referenced by relational constraints (ForeignKey, ManyToMany, etc.)

pip install -e "git+"

To start autocaching model instances, add a CacheController to your model:

from django.db import models
from cachemagic import CacheController

class myModel(models.Model):
f1 = models.IntegerField()
f2 = models.TextField()

cache = CacheController()


When using cachemagic, you should avoid django operations that update multiple
rows at once, since these operations typically don't emit the signals that
cachemagic relies on for cache invalidation. This includes methods like

Find the complete documentation at [](

Big thanks to [Travis Fischer]( for drafting
a lot of documentation and tests!

Release History

This version
History Node


Download Files

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

File Name & Hash SHA256 Hash Help Version File Type Upload Date
(16.0 kB) Copy SHA256 Hash SHA256
Source Jan 11, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting