Cache-Control中的私有vs公共 [英] Private vs Public in Cache-Control

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

问题描述

请你描述一个示例,说明在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 的该差是:

公共:
设置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?

推荐答案

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

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可能在您和您之间有一个不可见的代理互联网,即缓存网页,以减少所需的带宽量并降低成本。通过使用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.

作为规则拇指,如果它是每个人可以访问的东西(例如,此页面中的徽标)缓存控制:公共可能更好,因为缓存它的人越多,您需要的带宽就越少。如果它是与连接用户相关的东西(例如,此页面中的HTML包含我的用户名,那么它对任何其他人都没用)缓存控制:私有会更好,因为代理将缓存数据其他用户不会请求,也可能会保留您不希望保存在您不信任的服务器中的数据。

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.

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

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