Apache、mod_cache 和 Cookie
我正在考虑使用 mod_cache。然而,我想要由 Apache 缓存的页面(由 php 生成)通常包含该用户的登录名(“您以...登录”)。所以我不能只为所有用户缓存一个页面。
登录状态由cookie确定。所以我想我可以(在 PHP 中)在每个页面中包含一个“Vary: Cookie”标头。如果我对 RFC 2616 的理解是正确的,这应该指示 Apache(或任何其他)缓存算法为用户代理发送的每个单独的 Cookie 值缓存一个单独的页面。
因此,如果浏览器没有发送 cookie(用户已注销),则缓存的响应将与带有 Cookie 的请求的缓存响应分开:state=89898XAAJ(用户以“Jacob”身份登录),并且再次保留与带有 Cookie 的请求的缓存响应分开:state=XXAIU2389(用户以“Bob”身份登录)。如果一段时间后,用户请求相同的 URL 并使用 Cookie:state=89898XAAJ,他会看到正确的页面,其中包含“您以 Jacob 身份登录”(而不是其他缓存的页面)。
我的理解是否正确,是否会以这种方式工作,还是我在这里忽略了一些东西?
I'm thinking about using mod_cache. However, the pages (generated by php) that I want to have cached by Apache usually contain the login name of that user (“You are logged in as ...”). So I cannot just cache a single page for all users.
The login state is determined by a cookie. So I thought that I could (in PHP) include a ‘Vary: Cookie’ header in every page. If my understanding of RFC 2616 is correct, this should instruct the Apache (or any other) caching algorithm to cache a separate page for every individual Cookie value that is sent by the user agent.
So if no cookie is sent by the browser (user is logged out), the cached response is kept separate from the cached response to a request with Cookie: state=89898XAAJ (user is logged in as 'Jacob') and that is again kept separate from a cached response to a request with Cookie: state=XXAIU2389 (user is logged in as 'Bob'). And if, some time later, a user requests the same URL and uses Cookie: state=89898XAAJ, he is served the correct page with 'You are logged in as Jacob' in it (and not the other cached ones).
Is my understanding correct and is this going to work this way or am I overlooking something here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您所描述的方法是否有效。
如果没有,您可以尝试使用重写条件检查 cookie 值,并根据用户和登录状态重定向到缓存地址。
本页讨论基于 cookie 值的重写:
Check cookie and redirect with Apache
嗯,
乔
I'm not sure if the approach you've described will work or not.
If it doesn't, you could try checking the cookie value with a rewrite condition and redirect to the cached address based on the user and logged in status.
This page discusses rewriting based on cookie value:
Check cookie and redirect with Apache
Be Well,
Joe