django-cachepurge 0.3

Django Middleware and utilities that send "PURGE" request to an upstream cache

What is it?

This package allows django to purge HTTP cache when a model instance is changed or deleted. It does this by sending "PURGE" requests to one or more upstream HTTP cache (such as Squid or Varnish). This is inspired by Plone CacheFu components.


In put 'django_cachepurge' before any other application; else it may fail to register some models:


Add the middleware:




or if you have more than one cache:



Urls are extracted from models instances on post_save signal. Two sources are used:

  • instance.get_absolute_url(), if it exists
  • instance.get_purge_urls(), if it exists. The application expects a list of absolute paths similar to what is provided by get_absolute_url().

Purge request is sent when response has been computed: if an exception occurs the urls are not purged. Purge requests are asynchronous: worker threads handle that so that we don't have wait to complete all requests before returning the response.

Cache configuration

The cache must be configured to accept and handle "PURGE" requests from the server where the django application is hosted.


Bertrand Mathieu, Author

Change history

0.3 - 2011-04-01

  • Compatible with Django 1.3: don't import django.utils.thread_support
  • catch NoReverseMatch exception when trying to find an instance's url

0.2 - 2010-11-22

  • Accept to purge only site urls, converted if needed into their relative form (i.e, "/some/path/")

0.1a - 2009-05-25

  • 0.1a: 0.1 released missed some files
  • Initial release


Bertrand Mathieu




  • Development Status :: 5 - Production/Stable
  • Environment :: Web Environment
  • Framework :: Django
  • Intended Audience :: Developers
  • License :: OSI Approved :: GNU General Public License (GPL)
  • Topic :: Internet :: Proxy Servers
File Type Python Version Uploaded On Downloads
django-cachepurge-0.3.tar.gz Source April 1, 2011 2,864
Version Release Date
0.3 April 1, 2011
0.2 Nov. 22, 2010
0.1a May 25, 2009
Date Package Version Action
Aug. 24, 2015, 10:59 p.m. django-cachepurge 0.1a Release Created
Aug. 24, 2015, 10:59 p.m. django-cachepurge 0.2 Release Created
Aug. 24, 2015, 10:59 p.m. django-cachepurge 0.3 Release Created
Aug. 24, 2015, 10:59 p.m. django-cachepurge Package Created