缓存控制中的私有与公共

发布于 2024-09-14 16:10:25 字数 476 浏览 9 评论 0原文

您能否描述一个示例,说明 IIS 中托管的 ASP.NET 应用程序中公共缓存控制和私有缓存控制之间的差异。

我在 MSDN 中读到区别如下:

公开: 设置 Cache-Control: public 以指定响应可由客户端和共享(代理)缓存缓存。

私有:默认值。设置 Cache-Control: private 以指定响应只能在客户端上缓存,而不能由共享(代理服务器)缓存缓存。

我不确定我是否完全理解每个选择的利弊。何时使用或不使用它的例子会很好。

例如,如果我有两个托管同一应用程序的 Web 服务器,我该怎么办?如果我选择私人或公共,有什么需要注意的吗?

Can you please describe an example indicating difference between Public and Private Cache-Control in asp.net applications hosted in IIS.

I read in MSDN that the difference is the following:

Public:
Sets Cache-Control: public to specify that the response is cacheable by clients and shared (proxy) caches.

Private: Default value. Sets Cache-Control: private to specify that the response is cacheable only on the client and not by shared (proxy server) caches.

I am not sure I have completely understood the pros and cons from each choice. An example for when to or not to use it would be great.

For example what should I do if i have two web servers hosting the same application? Is there anything to watch out if I choose Private or Public?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赠我空喜 2024-09-21 16:10:25

唯一的区别是,使用 Private 时,您不允许代理缓存通过它们传输的数据。最后,这一切都归结为您发送的页面/文件中包含的数据。

例如,您的 ISP 可能在您和互联网之间有一个隐形代理,即缓存网页以减少所需的带宽量并降低成本。通过使用cache-control:private,您指定它不应缓存页面(但允许最终用户这样做)。如果您使用cache-control: public,则表示每个人都可以缓存该页面,因此代理将保留一个副本。

根据经验,如果每个人都可以访问它(例如,本页中的徽标)cache-control: public 可能会更好,因为缓存它的人越多,您的带宽就越少会需要的。如果它是与连接的用户相关的内容(例如,此页面中的 HTML 包含我的用户名,因此对其他人没有用)cache-control: private 会更好,因为代理将缓存数据其他用户不会请求,并且他们也可能将您不希望保留的数据保留在您不信任的服务器中。

当然,所有非公开的内容都应该有一个私有缓存。否则,数据可能会存储在中间代理服务器中,任何有权访问该数据的人都可以访问该数据。

The only difference is that with Private you are not allowing proxies to cache the data that travels through them. In the end, it all boils down to the data contained in the pages/files you are sending.

For example, your ISP could have an invisible proxy between you and the Internet, that is caching web pages to reduce the amount of bandwidth needed and lower costs. By using cache-control:private, you are specifying that it shouldn't cache the page (but allowing the final user to do so). If you use cache-control: public, you are saying that it's okay for everyone to cache the page, and so the proxy would keep a copy.

As a rule of thumb, if it's something everybody can access (for example, the logo in this page) cache-control: public might be better, because the more people that cache it, the less bandwidth you'll need. If it's something that is related to the connected user (for example, the HTML in this page includes my username, so it won't be useful to anyone else) cache-control: private will be better, as the proxies would be caching data that won't be requested by other users, and they might also be keeping data that you don't want to be kept in servers that you don't trust.

And, of course, everything that is not public should have a private cache. Otherwise the data might be stored in a middle proxy server, were it could be accessed by anyone with access to it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文