代理缓存 - 怎么样? [英] Proxy cacheing - What about cookies?

查看:231
本文介绍了代理缓存 - 怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了 http://code.google.com/speed/page-speed/docs /caching.html 。它说,代理服务器可能会缓存cookie。我需要说明一下。




假设我的文件头是这样的: Cache-Control max-age = 604800,public

Q.1。使用此标题,来自个人计算机的Cookie可以缓存在代理上服务器何时访问静态文件? (然后,下一个访问该文件的人是否会接受他人的cookies?)






现在,我们假设缓存代码像 Cache-Controlmax-age = 7200,代理重新验证代替。
Q.2。代理服务器上cookie缓存的区别是什么?






现在我有一个关于实际设置> Cookie的文件的问题(如Javascript或PHP)。
Q.3。 Cookie是否会在代理服务器上缓存这些类型的文件被访问?或者缓存与静态文件相同?






如果您想知道,我问这些问题的原因是因为我不会将一个人的Cookie作为代理缓存,从而转移给另一个人。所以任何澄清都会有帮助。非常感谢!






编辑:

谢谢非常适合所有的帮助。但我仍然需要更多的澄清。

如果我使用头文件 Cache-Controlmax-age = 604800,public,任何请求cookie( Cookie )或响应cookie( Set-Cookie )都会被传送到另一个 另一个用户的计算机 (因为它在缓存中)?或者它会被缓存只为个人用户的浏览?那么如果设置是 Cache-Controlmax-age = 7200,proxy-revalidate呢?再次感谢。

解决方案

它取决于代理和 Vary 响应头。通常,代理不会缓存对具有 Cookie 标头的请求的响应。但是,这并不能保证。



当指定 Cache-Control 标头时,指令 public ,您要求代理共享不同客户端之间的缓存。这大概不是你的意图,所以你应该指定 private 来代替。请参阅: http://www.mnot.net/cache_docs/#CACHE-CONTROL


代理服务器上cookie缓存的区别是什么?

并非如此。它所做的只是告诉代理它不应该从一个陈旧的缓存中提供服务。它不影响如何控制缓存。


访问这些类型的文件时,Cookie是否会缓存在代理服务器上?或者缓存与静态文件相同?


对于http级别的软件(例如代理),没有区别静态和动态内容之间。 Cookie只是与请求( Cookie 标头)一起发送或与响应一起发送的HTTP标头( Set-Cookie 标题)



如果您在浏览器中设置cookie(通过Javascript或从服务器端通过 Set-Cookie 标题),浏览器将发回cookie并将所有后续请求发送到同一个域。它通过在请求中添加 Cookie 标头来完成此操作。 编辑


我确实希望将我的实际文件缓存在代理上,而不是单个用户的Cookie。如何做到这一点?


您需要避免缓存任何响应:




  • 包含一个 Set-Cookie 标题(因为这会被代理缓存)

  • 服务器端存在副作用(例如,应用程序接收请求很重要 - 例如,缓存跟踪像素是没有意义的)

  • 请求的内容 Cookie 标题决定了呈现的内容(例如,打印Welcome Back,John Doe或其他自定义)


你将如何做到这一点取决于你的后端技术。您的应用程序知道 Cookie 头对于响应是否重要,或者响应是否可能包含 Set-Cookie 头文件。



在我使用的应用程序框架中,有一个用于设置缓存到期头的函数。如果我在相同的请求访问cookie中调用该cookie,则会出现错误。这确保我不会不小心要求代理缓存私人内容。您需要在您的应用程序中实现类似的逻辑。



或者,您可以配置边缘级代理以执行相同的操作。如果我没有使用标头Cache-Control的文件max-age = 604800,那么通常是在完全控制应用程序的情况下完成的。 $ b


,公共,将任何请求cookie(Cookie)或响应cookie(Set-Cookie)传输到另一个用户的计算机(因为它在缓存中)?或者它会被缓存,仅用于该用户的浏览?


请求cookie不会被缓存,也不会被传输到任何地方。缓存响应( Set-Cookie 。由于您将 cache-control 指定为公共,它将在所有客户端之间共享。请注意,即使请求cookie未被直接缓存,如果您在页面中呈现某些依赖于Cookie的内容(例如,如果您使用Cookie进行服务器端会话状态,如身份验证),您将缓存个性化响应。


如果设置是Cache-Controlmax-age = 7200,proxy-revalidate,那么怎么办?再次感谢。


同样的事情。 proxy-revalidate 通知任何代理(如果有的话)它们可能不会提供过时的缓存。例如。一旦7200秒过去了,应立即清除缓存。如果没有这个,缓存一般会继续提供陈旧的缓存,然后在达到超时后在后台获取全新副本。或不 - 取决于代理。


I read http://code.google.com/speed/page-speed/docs/caching.html. It says that proxy servers may cache cookies. I need clarification.


Let's say I have this header for my files: Cache-Control "max-age=604800, public"
Q.1. With this header, will the cookies from a person's computer be cached on the proxy server when a static file is accessed? (Then, would the next person to access the file pick up the other person's cookies?)


Now, let's say the cache code went like Cache-Control "max-age=7200, proxy-revalidate" instead.
Q.2. What would be the difference as far as cookie cacheing on the proxy server?


Now I have a question about files that actually set cookies (such as Javascript or PHP).
Q.3. Will cookies be cached on the proxy server when these kinds of files are accessed? Or is the cacheing the same as static files?


In case you are wondering, the reason I ask these things is because I do not one person's cookies to be proxy cached, and thus transferred to another person. So any clarification would really help. Thank you so much!


Edit:
Thank you very much for all the help. But I still need a little more clarification.

If I have files using header Cache-Control "max-age=604800, public", will any request cookies (Cookie) or response cookies (Set-Cookie) be transferred to another user's computer (since its in the cache)? Or will it be cached only for that individual user's browsing? What about if the setting is Cache-Control "max-age=7200, proxy-revalidate"? Thanks again.

解决方案

It depends on the proxy and on the Vary response-header. In general, proxies will not cache a response to a request that has a Cookie header. However, that is not really guaranteed.

When you specify your Cache-Control header with the directive public, you are asking proxies to share the cache between different clients. That is presumably not your intention, so you should specify private instead. See: http://www.mnot.net/cache_docs/#CACHE-CONTROL

What would be the difference as far as cookie cacheing on the proxy server?

Not really. All it does is it tells the proxy that it shouldn't serve from a stale cache. It doesn't affect how the cache is controlled.

Will cookies be cached on the proxy server when these kinds of files are accessed? Or is the cacheing the same as static files?

For a http level piece of software (e.g. a proxy), there is no difference between static and dynamic content. Cookies are merely http-headers that are sent with a request (Cookie header) or sent with a response (Set-Cookie headers)

If you set a cookie in the browser (either through Javascript or from the server side, through a Set-Cookie header), the browser will send the cookie back with all subsequent requests to the same domain. It does this by adding a Cookie header with the requests.

Edit:

I do want my actual files to be cached on the proxy, but not individual users' cookies. How do I do this?

You need to avoid caching any response that either:

  • Contains a Set-Cookie header (Since this would get cached by the proxy)
  • There is a side effect on the server side (E.g. it's important for your application to receive the request - For example, it wouldn't make sense to cache a tracking pixel)
  • Where the contents of the requests Cookie header determines what gets rendered (E.g. printing "Welcome back, John Doe" or other customisation)

How exactly you'll do that depends on your backend technology. It's your application that knows whether the Cookie header is significant for the response or whether a response could potentially contain a Set-Cookie header.

In the application framework that I use, there is a function for setting cache-by-expires headers. If I call that and within the same request access cookies, I'll get an error. This ensures that I don't accidentally ask a proxy to cache private content. You need a similar logic implemented in your application.

Alternatively, you can configure an edge-level proxy to do the same thing. That's usually done if you don't control the application completely.

If I have files using header Cache-Control "max-age=604800, public", will any request cookies (Cookie) or response cookies (Set-Cookie) be transferred to another user's computer (since its in the cache)? Or will it be cached only for that individual user's browsing?

The request cookies are not cached and will not be transferred anywhere. The response (Set-Cookie) is cached. Since you specify cache-control as public, it will be shared amongst all clients. Note that even though the request cookie isn't directly cached, if you render something in the page, that relies on cookies (E.g. if you use the cookie for server side session state, such as authentication), you will cache the personalised response.

What about if the setting is Cache-Control "max-age=7200, proxy-revalidate"? Thanks again.

Same thing. proxy-revalidate informs any proxies (if there are any) that they may not serve a stale cache. E.g. once the 7200 seconds have passed, the cache should be purged immediately. Without this, caches will generally keep serving a stale cache and then fetch a fresh copy in the background, once the timeout has been reached. Or not - Depends on the proxy.

这篇关于代理缓存 - 怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆