Didn"t forge 2015-12-03 13:02 采纳率: 25%
浏览 1916

如何在Flask中禁用缓存?

我有一些缓存问题。

我正在运行一个很小的Web应用程序,该应用程序读取一帧并将其保存到磁盘,然后在浏览器窗口中显示。

我知道,这可能不是最好的解决方案,但是每次我以相同的名称保存此读取帧时,浏览器都会对其进行缓存。

我尝试使用html元标记,但没有成功:

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

另外,我已经尝试过这一步骤(特定于flask):

resp.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
resp.headers["Pragma"] = "no-cache"
resp.headers["Expires"] = "0"

这是我尝试修改 resp 标头的方式:

r = make_response(render_template('video.html', video_info=video_info))

r.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
r.headers["Pragma"] = "no-cache"
r.headers["Expires"] = "0"

仍然在Google Chrome和Safari中进行缓存。 这里可能是什么问题?

  • 写回答

3条回答 默认 最新

  • weixin_33738578 2015-12-03 13:48
    关注

    OK,

    finally it worked with this:

    @app.after_request
    def add_header(r):
        """
        Add headers to both force latest IE rendering engine or Chrome Frame,
        and also to cache the rendered page for 10 minutes.
        """
        r.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
        r.headers["Pragma"] = "no-cache"
        r.headers["Expires"] = "0"
        r.headers['Cache-Control'] = 'public, max-age=0'
        return r
    

    If you add this, this function will called after each request done. Please,see here

    I would be happy, if anyone could explain me why this headers overwriting did not work from the page handler?

    Thank you.

    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献