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.
Installation
pip install django2-manager-cache
Caching strategy
Cache results for a model on load.
Evict cache for model on update.
Usage
Add to installed apps:
INSTALLED_APPS = ( ... 'django2_manager_cache', ... )
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 # https://docs.djangoproject.com/en/2.2/topics/db/managers/#base-managers # class Meta: # base_manager_name = 'objects'
Define cache backend for django2_manager_cache.cache_backend in settings.py. The backend can be any cache backend that implements django cache API.:
CACHES = { 'django2_manager_cache.cache_backend': { 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', 'LOCATION': '127.0.0.1:11211', } }
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') m.save() c = Car(make=m, model='Model S', year=2015) c.save() d = Driver(first_name ='ABC', last_name='XYZ') d.save() d.cars.add(c) 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.11, 2.0, 2.1, 2.2
History
1.0.1
Include docs
1.0.0
First beta release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django2_manager_cache-1.0.1.tar.gz
.
File metadata
- Download URL: django2_manager_cache-1.0.1.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 364602c1cdf92aeaaab856c9adacf23c3ab29e61f1731748ab2af08c28a9e208 |
|
MD5 | 44d71cd403c1c31d04a654f886ec2629 |
|
BLAKE2b-256 | 2f8484bec943c79a9400a3103974cbd8992783978b2be65e26fb09349c888a8c |
File details
Details for the file django2_manager_cache-1.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: django2_manager_cache-1.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 532299e248178a84c348248d042f3f8c24a6689cea2b917696068c0fe2e0187a |
|
MD5 | 74c19546e766ac186518c4a8f8efcde7 |
|
BLAKE2b-256 | 20652b79523846b64ab6a2b243da03e1d07b0543f88dd785958e39d58f6a3148 |