- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个非常复杂的基于 Django 1.11 的网络应用程序。前一段时间,用户开始报告他们正在获取“其他人的 View ”——memcached 为他们提供了装饰器 @cache_page(xx)
缓存的 html,而不区分缓存宽限期内的 session 。
经过进一步调查,我发现在某些情况下 Vary: Cookie
header 丢失并且提供了错误的“ session ”。奇怪的是,它仅在使用 curl 查询后端时显示(没有 session 、用户等 -> 后端服务登录在缓存 View 中)。
不幸的是,这个问题真的很难重现,有时会发生,有时不会。我什至从头开始构建一个简单的 Django 应用程序,看看我是否可以检查是什么原因。观察到的是,当删除 @cache_page
或添加 login_required
时,问题不会发生。
我最终从 View 中删除了所有@cache_page 装饰器,此后在生产中未观察到该问题,但这是一种解决方法,我想知道原因是什么。
如果任何人有任何提示可能是什么原因,将不胜感激!
最佳答案
您可能遇到了这个 open bug :
Since view decorators run on the outgoing response first, before response middleware, the
cache_page
decorator caches the response before any of the mentioned response middlewares have a chance to add their Vary headers. This means two things: 1) the cache key used won't include the headers the response ought to vary on, and Django may later serve that response to users who really shouldn't get it, and 2) when that cached response is later served to a user, it still won't include theVary
header that it should have, and thus may also be cached wrongly by an upstream HTTP cache.
换句话说,在缓存响应时 SessionMiddleware
还没有机会设置 Vary: Cookie
header ,因此所有 session 都会共享相同的缓存键。
您可以通过显式指定 Vary
header 来解决这个问题。例如:
from django.views.decorators.cache import cache_page
from django.views.decorators.vary import vary_on_cookie
@cache_page()
@vary_on_cookie()
def my_view():
pass
关于python - Django 缺少 Vary :Cookie header for cached views,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45793163/
我将数据库从 sqlite 更改为 postgresql 以用于我网站的生产,但出现此错误。当我在本地使用 sqlite 时,它没有出现这个错误。使用 Django。 ProgrammingErr
对于同一资源的请求,HTTP 服务器有时使用 Vary: * 有时使用 Vary: Foo 响应是否有任何原因? 缓存应该做什么,如果在收到(和缓存)两个响应后,它会收到一个带有匹配的 Foo hea
对于我的应用程序,我创建了一个 SQL 文件补丁以将列 user_name 添加到现有表中: CREATE OR REPLACE FUNCTION add_col( _tbl VARCHAR,
我希望有人能帮忙 1) 在小平面图中跨面板改变 x 轴的格式 2) 仅在刻面左侧显示黄土较光滑。 左边是更长的历史,右边是过去十二个月。 真实数据集有更多数据(更多时间和更多变量),因此这些问题变得更
当我尝试在数组数组中搜索一个数组值时出现上述错误。我的代码: sequelize.define('room', { 'id' : {'type' : DataTypes.INTEGER
昨天我们将 PostgreSQL 数据库升级到了 9.1.3 版本。我们认为我们已经测试并准备好了一切,但我们错过了一个功能。它返回这样的表类型: CREATE OR REPLACE FUNCTION
我是 SO 和 postgres 的新手所以请原谅我的无知。尝试使用类似于本文中的解决方案在 postgres 中获取图形的集群 Find cluster given node in PostgreS
我在 MacBook Pro 上使用 GLFW 3 和 OpenGL 4 + GLSL 4。 启动程序时出现以下语法错误: ERROR: 0:5: 'varying' : syntax error s
上下文 我正在构建一个针对 5.0+ 的 Android 应用程序,它使用 BLE 连接到多个外围设备。这些外围设备中的每一个都有许多(~10)个特性。理想情况下,我想订阅这些特征中每一个特征的更改通
根据我对 this question 的回答中所解释的理解您可以为您想要的任何设备调整 Storyboard 上的任何组件的大小,这就是问题发生的地方..我有一张图片,它的常规分辨率是:353x229
我想确保我的某些回复不会被任何人缓存。建议的选项之一是设置 Vary: *。 不幸的是,如果我添加 add_header "Vary""*";,启用了 gzip 支持的 nginx 会返回两个 Var
我试图弄清楚为什么我的Magento 2.2.6商店显示标题: vary: Accept-Encoding,User-Agent 问题是“用户代理”使我的缓存无法正常工作。 我的商店的 build 方
最近,我尝试在该领域之前进行的工作的基础上创建一个股票市场预测程序,其中通过 Python 中的 Keras 模块创建的神经网络接收来自 Quandl 的调整后的股票价格信息,利用上述信息来训练自己。
我正在使用 moment.js 和 Moment Timezone 来处理不同时区的 ISO 日期。然而,我一定是做错了什么,因为我从解析中得到的结果是完全错误的,即使据我所知我并没有做任何奇怪的事情
在 Android Studio 2.2.2 中,我在 AndroidManifest.xml 文件中有一个错误 Resources referenced from the manifest cann
在我的用户模型上运行一个简单的语句,但不断收到有关运算符与任何给定参数不匹配的错误。我以前从未遇到过这样的事情,也不知道如何处理。我知道我可能必须添加类型转换,但在我的 POSTGRES 数据库中,列
我因异常而失去理智,我需要你的帮助。 我已经将查询写入映射器,该映射器根据两个条件从表中检索记录:列表中的“位置”和另一个列表中的“技能”。 所以,基本上,如果用户选择了不止一种技能来查找,查询将恢复
我需要帮助来查看以下查询,我有如下表格: CREATE TABLE "MasterDivision" ( "DivisionID" bigserial NOT NULL, "Divis
我的 postgres 数据库表有一个列位置是字符 varying[]。在我的表的 nestjs 实体中,我有以下位置列- @Column("character varying",{array:tr
我的模型有一个 SlugField。当我尝试将 slug 字段设置为比字段的 max_length 参数(默认为 50)长的字符串来保存此模型的实例时,我从 Postgresql 收到以下错误:val
我是一名优秀的程序员,十分优秀!