Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Helpful bits to make caching and cache invalidation as painless as possible in Django!

tree: 6f51cd0b2e

Fetching latest commit…

Cannot retrieve the latest commit at this time


Autocache 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+git://"


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

from django.db import models
from autocache import CacheController

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

    cache = CacheController()


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

Find the complete documentation at

Running the tests

Django-Autocache has a sample django application that tests the caching machinery. To run tests, start by cloning the autocache repository and entering the test_project directory.

The tests run using memcached and pylibmc. You can change the backend by editing autocache/tests/ (TODO: get the test suite to run multiple times with different backends)

  • Start two memcached servers (testing multicache)
    • memcached -p 11211 -U 0
    • memcached -p 11212 -U 0
  • Change into the autocache/test_project/ directory and run test


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

Something went wrong with that request. Please try again.