伪代码如何:
from flask import Flask, render_template
from flask_cache import Cache
import os
basedirs = os.path.abspath(os.path.dirname(__file__))
basedir = basedirs + '/cache'
app = Flask(__name__)
app.debug = True
cache = Cache(app, config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': basedir})
@app.route('/')
@cache.cached(timeout=50)
def index():
#这视图里面有些数据处理,渲染给页面.具体代码就不贴了
a= 'test'
return render_template('index.html',a=a)
@app.route('/list/<name>')
def list():
start = time.time()
return render_template('index.html', start=start)
if __name__ == '__main__':
app.run()
index已经缓存好数据了,并保存到basedir了.
我想根据比如用户1访问:
www.baidu.com/list/1 缓存下来
www.baidu.com/list/2 缓存下来
用户2来访问:
www.baidu.com/list/1 这个就直接去调用之前缓存下来的内容
答案在这里http://blog.csdn.net/jmilk/ar... 解决了
缓存数据后,会自动调用缓存数据.