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

如何在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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog