Cache manager for django models
Project description
django-cache-manager
=====================
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](https://travis-ci.org/vijaykatam/django-cache-manager.svg?branch=master)](https://travis-ci.org/vijaykatam/django-cache-manager)
[![Coverage Status](https://img.shields.io/coveralls/vijaykatam/django-cache-manager.svg)](https://coveralls.io/r/vijaykatam/django-cache-manager)
[![PyPI version](https://badge.fury.io/py/django-cache-manager.svg)](https://badge.fury.io/py/django-cache-manager)
## Installation
```sh
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
```
INSTALLED_APPS = (
...
'django_cache_manager',
...
)
```
Define cache backend for `django_cache_manager.cache_backend` in `settings.py`. The backend can be any cache backend
that implements django cache API.
```
CACHES = {
'django_cache_manager.cache_backend': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}
```
```
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.
```sh
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
```sh
make test
```
##### Supported Django versions
Supported - 1.5, 1.6, 1.7, 1.8, 1.9, 1.10
History
-------
0.5.1
---
* Avoid spurious cache miss when query is empty
* Fixed error: 'NoneType' object has no attribute `\_meta`
0.5
---
* Add support for Django 1.10
0.4.1
---------------------
* Update requirements to Django<1.10
0.4
---------------------
* Support for django 1.9
0.3
---------------------
* Support for django 1.8
0.2
---------------------
* Use django.core.cache.caches available in django 1.7 for efficient cache backend access
0.1.5
---------------------
* [BUGFIX] - Fix for non-ascii characters in query.
0.1.4
---------------------
* [BUGFIX] - Fix cache eviction on bulk updates for models that have a ManyToManyField with an intermediate(through) model.
0.1.3
---------------------
* [BUGFIX] - Fix cache eviction for models that have a ManyToManyField with an intermediate(through) model.
0.1.2
---------------------
* [BUGFIX] - Properly handle passing of an empty iterable to '\__in' filter args. Related Django bug: https://code.djangoproject.com/ticket/12717
0.1.1
---------------------
* [BUGFIX] - Invalidate related model caches for changes, needed for select_related queries.
0.1.0
---------------------
* Test coverage
* Cache invalidation for manytomany relation
0.1.0-beta.1
---------------------
* First beta release
=====================
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](https://travis-ci.org/vijaykatam/django-cache-manager.svg?branch=master)](https://travis-ci.org/vijaykatam/django-cache-manager)
[![Coverage Status](https://img.shields.io/coveralls/vijaykatam/django-cache-manager.svg)](https://coveralls.io/r/vijaykatam/django-cache-manager)
[![PyPI version](https://badge.fury.io/py/django-cache-manager.svg)](https://badge.fury.io/py/django-cache-manager)
## Installation
```sh
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
```
INSTALLED_APPS = (
...
'django_cache_manager',
...
)
```
Define cache backend for `django_cache_manager.cache_backend` in `settings.py`. The backend can be any cache backend
that implements django cache API.
```
CACHES = {
'django_cache_manager.cache_backend': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}
```
```
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.
```sh
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
```sh
make test
```
##### Supported Django versions
Supported - 1.5, 1.6, 1.7, 1.8, 1.9, 1.10
History
-------
0.5.1
---
* Avoid spurious cache miss when query is empty
* Fixed error: 'NoneType' object has no attribute `\_meta`
0.5
---
* Add support for Django 1.10
0.4.1
---------------------
* Update requirements to Django<1.10
0.4
---------------------
* Support for django 1.9
0.3
---------------------
* Support for django 1.8
0.2
---------------------
* Use django.core.cache.caches available in django 1.7 for efficient cache backend access
0.1.5
---------------------
* [BUGFIX] - Fix for non-ascii characters in query.
0.1.4
---------------------
* [BUGFIX] - Fix cache eviction on bulk updates for models that have a ManyToManyField with an intermediate(through) model.
0.1.3
---------------------
* [BUGFIX] - Fix cache eviction for models that have a ManyToManyField with an intermediate(through) model.
0.1.2
---------------------
* [BUGFIX] - Properly handle passing of an empty iterable to '\__in' filter args. Related Django bug: https://code.djangoproject.com/ticket/12717
0.1.1
---------------------
* [BUGFIX] - Invalidate related model caches for changes, needed for select_related queries.
0.1.0
---------------------
* Test coverage
* Cache invalidation for manytomany relation
0.1.0-beta.1
---------------------
* 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
File details
Details for the file django-cache-manager-redux-0.5.1.1.tar.gz
.
File metadata
- Download URL: django-cache-manager-redux-0.5.1.1.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bd4f704f5b65b4d99314c2e4fc3df09dec4663d314d917d36e64b44ba8900ea |
|
MD5 | d71094531f88dac352b2ba900325de05 |
|
BLAKE2b-256 | a4e0b55348668de7ddc3f3a3f9dd7eae88c919373f4be707d516f889f376d8a5 |