pip install django-cacheops python CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', 'LOCATION': '127.0.0.1:11211', } } python from cacheops import cached from models import Post @cached() def get_post(id): return Post.objects.get(id=id) python @cached() def get_post_title(id): return Post.objects.get(id=id).title @cached() def get_post_content(id): return Post.objects.get(id=id).content python from cacheops import cache_page from django.urls import reverse def my_view(request): return render(request, 'my_template.html')


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