pip install django-cache-machine python CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', 'LOCATION': '127.0.0.1:11211', } } python INSTALLED_APPS = [ ... 'cache_machine', ... ] python manage.py migrate cache_machine python class YourModel(models.Model): ... def cache_key(self): return f'yourmodel:{self.pk}' ... python your_model_obj.save() your_model_obj.invalidate_obj_cache() python from cache_machine.api import cache, invalidate python YourModel.objects.filter(...).cache() python YourModel.objects.filter(...).invalidate()


上一篇:
下一篇:
切换中文