python
pip install django-cache-machine
python
INSTALLED_APPS = [
...
'cache_machine',
...
]
python
from django.db import models
from cache_machine.models import CachingMixin
class Product(CachingMixin, models.Model):
name = models.CharField(max_length=100)
price = models.DecimalField(max_digits=10, decimal_places=2)
...
python
from django.db import models
from cache_machine.models import CachingMixin
from cache_machine import cnf
class Product(CachingMixin, models.Model):
name = models.CharField(max_length=100)
price = models.DecimalField(max_digits=10, decimal_places=2)
cache_key_includes_pk = True
cache_machine_kwargs = {
'local_get_timeout': 60
}
class Meta:
cache_name = cnf.CACHE_NAME