【发布时间】:2020-01-20 19:19:33
【问题描述】:
我有一个具有多个 API 的 Flask 应用程序,我使用 POST 请求访问其中一个 API,并在正文中获取数据以及一些标头,例如 student_id。此 API 根据 headers 中传递的 student_id 返回学生结果。
我已经在 pycharm IDE(本地)中运行它,它可以 100% 运行,其中对于每个不同的 student_id,都会返回不同的结果。否则(student_id 未通过)返回错误请求。
但是当它被部署到 AWS (Elasticbean stalk) 中时,任何 student_id 的结果都是相同的,即使标头中没有 student_id,它仍然返回结果(在此 API 上发出的第一个请求的结果相同)。
在我看来,我想这是一个缓存问题,所以我尝试添加一个装饰器 @app.after_request 但它没有用
@application.after_request
def after_request(response):
response.headers['Last-Modified'] = str(http_date(datetime.now() - timedelta(days=1)))
response.headers["Cache-Control"] = "'no-store, no-cache, must-revalidate, post-check=0,
pre-check=0, max-age=0'"
response.headers["Expires"] = '-1'
response.headers["Pragma"] = "no-cache"
return response
【问题讨论】:
标签: python amazon-web-services api caching flask