安装模块
pip3 install Flask-Caching
使用方式
from flask import Flask
from flask_caching import Cache
config = {
"DEBUG": True, # some Flask specific configs
"CACHE_TYPE": "SimpleCache", # Flask-Caching related configs
"CACHE_DEFAULT_TIMEOUT": 300
}
app = Flask(__name__)
# tell Flask to use the above defined config
app.config.from_mapping(config)
cache = Cache(app)
@app.route('/')
def index():
cache.set('name', 'xxx')
return 'index'
@app.route('/get')
def get():
res=cache.get('name')
return res
if __name__ == '__main__':
app.run()
标签:__,name,flask,app,cache,Flask,模块
From: https://www.cnblogs.com/wellplayed/p/18056927