flask 插件使用方法

 

flask-caching

 

1 . 安装  

pip install flask-caching

  

2. 初始化 

// 初始化 定义 
from flask cache import Cache
cache =Cache(config={
  'CACHE_TYPE': 'simple',   # 页面缓存类型
})
cache.init app(app=app) # 初始化

  

3. 使用

// 在视图函数上添加缓存
@blue.route('/')
@cache.cached(timeout=30)
def home():
  print('加载数据')
  return 'home

  

 

posted @ 2024-11-01 10:30  我在春天等伱  阅读(40)  评论(0)    收藏  举报