看了一下 Flask-Cache 的文档,比如:
from flask import Flask
from flask.ext.cache import Cache
app = Flask(__name__)
# Check Configuring Flask-Cache section for more details
cache = Cache(app,config={'CACHE_TYPE': 'simple'})
cache = Cache(config={'CACHE_TYPE': 'simple'})
# cache = Cache(app, config={'CACHE_TYPE': 'redis'})
app = Flask(__name__)
cache.init_app(app)
然后缓存视图函数:
@cache.cached(timeout=50)
def index():
return render_template('index.html')
1 、如果这个视图函数 index()是动态的内容,比如是用户的 Newsfeed 聚合页,这个 cache 是缓存每一个用户的 index 内容吗?
2 、文档里简单提到,在 config 里( Werkzeug 0.7 以上版本即可),可以把 CACHE_TYPE 的 simple 改用 redis 来代替,这个 redis 的缓存数据,可以通过 SQLAlchemy 从 MySQL 加载部分需要缓存的数据吗?
原链接:
http://www.pythondoc.com/flask-cache/index.html#flask.ext.cache.Cache.memoize
http://stackoverflow.com/questions/24589123/how-to-cache-sql-alchemy-calls-with-flask-cache-and-redis
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.