shell
pip install django-cache-machine
python
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
},
}
python
from cache_machine.api import CachedProxy
class MyModel(models.Model):
python
from cache_machine.api import cached_query
queryset = MyModel.objects.all()
python
from cache_machine.api import invalidate_obj, invalidate_model
python
class MyModel(models.Model):
def get_cache_key(self):
return f'mymodel:{self.pk}'
def get_cache_timeout(self):
my_model = CachedProxy(MyModel.objects.get(pk=1))