缓存控制中的私有与公共 [英] Private vs Public in Cache-Control

查看:18
本文介绍了缓存控制中的私有与公共的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否举例说明在 IIS 中托管的 asp.net 应用程序中公共和私有缓存控制之间的区别.

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

我阅读了 MSDN 区别如下:

I read in MSDN that the difference is the following:

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

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

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

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.

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

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?

推荐答案

唯一的区别是 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.

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

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.

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

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.

这篇关于缓存控制中的私有与公共的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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