我试图使用 Django Cache 来改善我的观点。效果很好,400 毫秒到 8 毫秒是完美的。但是当用户第一次访问页面时,Django 缓存页面在标题中包含用户信息,当我尝试注销时,页面继续显示用户信息。
我也尝试在模板中使用缓存,但不好,我的问题来自视图,所以继续 400 毫秒。
我的设置.py
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'unique-snowflake',
}
}
我的观点.py
@cache_page(60 * 15)
def list(request, tag_slug=None):
page = request.GET.get('page')
data = questions_controller.list_questions(request, tag_slug, None, page)
if data:
return render(request, 'questions/list.html', data)
return page_not_found(request, "Page not found")