服务器缓存
1.配置settings.py文件
CACHES = {
‘default‘: {
‘BACKEND‘: ‘django.core.cache.backends.db.DatabaseCache‘,
‘LOCATION‘: ‘my_cache_table‘,
‘OPTIONS‘:{
‘MAX_ENTRIES‘: 300,
‘CULL_FREQUENCY‘: 2,
}
}
}
2.创建缓存表
python manage.py createcachetable
3.views.py文件 导入模块
from django.views.decorators.cache import cache_page
4.引用装饰函数 服务器内缓存30秒
@cache_page(30) # 单位s
def my_view(request):
return xxxxx
原文:https://www.cnblogs.com/chenlulu1122/p/11980731.html