【问题标题】:Caching issue when deployed flask app with SQLite on google App engine在谷歌应用引擎上使用 SQLite 部署烧瓶应用时出现缓存问题
【发布时间】:2020-07-22 07:41:38
【问题描述】:

我是谷歌云应用引擎的新生 :),我正在将我的烧瓶网络应用程序部署到谷歌应用引擎,来自 GAE 的一切看起来都很好, 但是当用户访问应用程序时,就会遇到问题。到目前为止,对我来说似乎是一个缓存问题。(希望有人帮助我,我会发疯)

问题描述: 用户从服务器端检索数据所需的任何操作。用户必须刷新页面才能重新加载更改(这有时用户按刷新超过 3 次。) 此外,在对象 ex.(table) 加载了从服务器检索到的数据后,如果用户再次按下会刷新页面。与采取任何操作之前一样加载的页面。 等等页面重新加载显示最新的另一个页面加载显示旧内容。

到目前为止我做了什么:

我将 app.yaml 更新为如下:

runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app

default_expiration: "2s"

env_variables:
  GOOGLE_APPLICATION_CREDENTIALS: 'vizionflow-5b8735ce1d20.json'

handlers:
- url: /static/css
  static_dir: static/css/
  expiration: '10s'

- url: /static/js
  static_dir: static/js/
  expiration: '5m'

error_handlers:
  - file: error_nopage.html

另外,我尝试添加

@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

感谢大家即使有想法也能提供帮助:)

【问题讨论】:

  • 您描述的动作是调用后端,您是否在前端实现了在此动作发生时重新加载的逻辑?还是在后端执行此操作,而您希望在前端反映这些操作?
  • 感谢您的回复,这些操作发生在他们调用后端时,而在前端它只是形成帖子到后端然后重新加载页面。

标签: python sqlite google-app-engine flask caching


【解决方案1】:

您是否检查过响应是否真的返回了您在 Python 中设置的标头? IIRC 它对我不起作用,因为 AppEngine 以某种方式覆盖了它们,所以我不得不将它们设置在 app.yaml 中,例如:

handlers:
  - url: /my/route
    script: auto
    secure: always
    http_headers:
      Cache-Control: no-cache

【讨论】:

    猜你喜欢
    • 2012-09-21
    • 2020-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-04
    • 1970-01-01
    • 1970-01-01
    • 2017-09-04
    相关资源
    最近更新 更多