Skip to main content

Cache manager for django models

Project description


Simple cache manager for django models that caches querysets for a model. Cache manager will cache any query that has been seen for a model. Model cache is evicted for any updates/deletes to the model. This manager is useful for models that don't change often.

[![Build Status](](
[![Coverage Status](](
[![PyPI version](](

## Installation

pip install django-cache-manager

### Caching strategy
* Cache results for a model on load.
* Evict cache for model on update.

## Usage

Add to installed apps
Define cache backend for `django_cache_manager.cache_backend` in ``. The backend can be any cache backend
that implements django cache API.

'django_cache_manager.cache_backend': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',

from django_cache_manager.cache_manager import CacheManager
class MyModel(models.Model):

#set cache manager as default
objects = CacheManager()


## Django shell
To run django shell with sample models defined in tests.
make shell
Sample models
from tests.models import Manufacturer
from tests.models import Car
from tests.models import Driver
m = Manufacturer(name='Tesla')
c = Car(make=m, model='Model S', year=2015)
d = Driver(first_name ='ABC', last_name='XYZ')
drivers = Driver.objects.select_related('car', 'manufacturer').all()

## Testing

To run tests

make test

##### Supported Django versions
Supported - 1.5, 1.6, 1.7, 1.8, 1.9, 1.10


* Avoid spurious cache miss when query is empty
* Fixed error: 'NoneType' object has no attribute `\_meta`

* Add support for Django 1.10

* Update requirements to Django<1.10

* Support for django 1.9

* Support for django 1.8

* Use django.core.cache.caches available in django 1.7 for efficient cache backend access

* [BUGFIX] - Fix for non-ascii characters in query.

* [BUGFIX] - Fix cache eviction on bulk updates for models that have a ManyToManyField with an intermediate(through) model.

* [BUGFIX] - Fix cache eviction for models that have a ManyToManyField with an intermediate(through) model.

* [BUGFIX] - Properly handle passing of an empty iterable to '\__in' filter args. Related Django bug:


* [BUGFIX] - Invalidate related model caches for changes, needed for select_related queries.


* Test coverage
* Cache invalidation for manytomany relation


* First beta release

Project details

Download files

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

Files for django-cache-manager-redux, version
Filename, size File type Python version Upload date Hashes
Filename, size django-cache-manager-redux- (14.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page