pip install django-cacheops python CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', 'LOCATION': '<memcache-server-ip>:<memcache-server-port>', } } CACHEOPS_REDIS = { 'host': '<redis-server-ip>', 'port': <redis-server-port>, 'db': 2, } CACHEOPS = { 'auth.*': {'ops': 'get', 'timeout': 60*15}, 'auth.User': {'ops': 'fetch', 'timeout': 60*15}, } python from django.db import models class Article(models.Model): title = models.CharField(max_length=100) content = models.TextField() class Meta: python from cacheops import cached_as @cached_as(Article) def get_articles(): return Article.objects.all()


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