Private vs Public in Cache-Control Ask Question

Private vs Public in Cache-Control Ask Question

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?

ベストアンサー1

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アクセスできるデータ (たとえば、このページのロゴ) の場合は、cache-control: public のほうが適している可能性があります。キャッシュする人が増えるほど、必要な帯域幅が少なくなるためです。接続しているユーザーに関連するデータ (たとえば、このページの HTML にはユーザー名が含まれているため、他のユーザーには役立ちません) の場合は、cache-control: private のほうが適しています。プロキシは他のユーザーから要求されないデータをキャッシュし、信頼できないサーバーに保存したくないデータも保存している可能性があるためです。

そしてもちろん、公開されていないものはすべてプライベート キャッシュを持つ必要があります。そうしないと、データが中間プロキシ サーバーに保存され、アクセス権を持つすべての人がアクセスできてしまう可能性があります。

おすすめ記事