Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Manager to Cache Django Models

Project description

  • Simple cache manager for Django 2 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


  • pip install django2-manager-cache

Caching strategy

  • Cache results for a model on load.
  • Evict cache for model on update.


Add to installed apps:


Add the manager to a django model:

from django2_manager_cache import CacheManager
class MyModel(models.Model):

   # set cache manager as default
   objects = CacheManager()

   # to use this manager with as related manager
   # class Meta:
   #    base_manager_name = 'objects'

Define cache backend for django2_manager_cache.cache_backend in The backend can be any cache backend that implements django cache API.:

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

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()


To run tests:

make test

Supported Django versions

Supported - 1.5, 1.6, 1.7, 1.8, 1.9, 1.11, 2.0, 2.1, 2.2



  • Include docs


  • 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 django2-manager-cache, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size django2_manager_cache-1.0.1-py2.py3-none-any.whl (10.3 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size django2_manager_cache-1.0.1.tar.gz (14.2 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