【发布时间】:2015-12-02 16:07:56
【问题描述】:
在视图中,我有这个缓存,应该可以节省一些昂贵的查询:
from django.core.cache import cache
LIST_CACHE_TIMEOUT = 120
....
topics = cache.get('forum_topics_%s' % forum_id)
if not topics:
topics = Topic.objects.select_related('creator') \
.filter(forum=forum_id).order_by("-created")
print 'forum topics not in cache', forum_id #Always printed out
cache.set('forum_topics_%s' % forum_id, topics, LIST_CACHE_TIMEOUT)
我使用这种方法缓存其他查询集结果没有问题,也想不出这种奇怪行为的原因,所以我很感激你的提示。
【问题讨论】:
标签: django django-queryset django-cache