# 导入需要的模块
from django.core.cache import cache
from . import models
def cache_index(change=False):
'''从redis中查询数据'''
a_list = cache.get('article_list')
if a_list is None or change == True:
print('去数据库中查找数据')
a_list = models.Article.objects.all()
print('将查询到的数据加载到缓存中')
cache.set('article_list', a_list)
return a_list