https://github.com/patriciaborges/django-model-cache
An easy-to-use cache for Django models.
https://github.com/patriciaborges/django-model-cache
cache django django-models
Last synced: 5 months ago
JSON representation
An easy-to-use cache for Django models.
- Host: GitHub
- URL: https://github.com/patriciaborges/django-model-cache
- Owner: patriciaborges
- License: mit
- Created: 2018-08-30T04:34:54.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-09-03T13:35:49.000Z (almost 7 years ago)
- Last Synced: 2025-10-05T20:13:11.230Z (10 months ago)
- Topics: cache, django, django-models
- Language: Python
- Size: 11.7 KB
- Stars: 13
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# django-model-cache
[](https://travis-ci.com/patriciaborges/django-model-cache)
An easy-to-use cache for Django models.
This code has been developed and used in a production environment for one year.
## How to use
There follows some examples of use. For further examples, see `tests/simple/tests.py`.
```python
from django.db import models
from django_model_cache import CacheController
import uuid
class Brand(models.Model):
name = models.CharField(max_length=128)
cache = CacheController(timeout=None)
class Product(models.Model):
code = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
brand = models.ForeignKey('Brand')
name = models.CharField(max_length=255)
cache = CacheController(fields=['code', ('brand_id', 'name')], related_fields=['brand'], timeout=None)
class Meta:
unique_together = ('name', 'brand')
# Get a product by pk.
product = Product.cache.get(pk=1)
# Get a product by a unique key.
product = Product.cache.get(code='A001')
# Load the related models.
product.load_related()
```
## How to test
Just run `tox` or install the dependencies and run `cd tests/ && ./manage.py test`.