Flask:缓存静态文件(.js,.css) [英] Flask: Caching static files (.js, .css)
问题描述
我希望缓存我的静态对象一个星期,另一方面我需要缓存函数/视图只有几分钟。
当我做下面是来自flask.ext.cache的缓存
。缓存
cache = Cache(config = {'CACHE_TYPE':'simple '))
cache.init_app(app)
@ cache.cached(timeout = 500)
def index():
return render_template 'index.html')
然后将所有视图,对象的缓存时间设置为相同的值, 500.怎么去解决这个问题?
我不会从我的python应用程序服务器静态文件,但试图委托网络服务器(nginx,apache ...)。
然后,您可以设置时间通过标题控制浏览器缓存多久。
I really could not find any resource on this. So how can I seperate caching of views/functions than static files (i.e. .css,.js)? I want to cache my static objects for a week, on the other hand I need to cache functions/views for only a few minutes.
When I do following
from flask.ext.cache import Cache
cache = Cache(config={'CACHE_TYPE': 'simple'})
cache.init_app(app)
@cache.cached(timeout=500)
def index():
return render_template('index.html')
then all views, objects' cache time is set to the same value, 500. How to go about it?
I would not server the static files from my python application but try to delegate that to the web server (nginx, apache... ). Then you could set the time to expire through headers controlling how long should the browser cache them.
这篇关于Flask:缓存静态文件(.js,.css)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!