pip install django-cache-machine
python
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'django_cache',
}
}
CACHE_MACHINE_ENABLED = True
python
from django.db import models
from cache_machine.models import CachingMixin
class User(CachingMixin, models.Model):
username = models.CharField(max_length=100)
email = models.EmailField()
python
user = User.objects.get(id=1)
user.invalidate_cache()