HttpCacheability.NoCache和HttpCacheability.ServerAndNoCache有什么区别?

时间:2015-07-30 09:21:51

标签: c# asp.net-mvc caching

之间有什么区别
  • HttpCacheability.NoCache
  • HttpCacheability.Server
  • HttpCacheability.Public
  • HttpCacheability.Private
  • HttpCacheability.ServerAndNoCache

我们应该使用哪一个?

2 个答案:

答案 0 :(得分:2)

来自MSDN

  • NoCache:
      

    设置Cache-Control:no-cache标头。如果没有字段名称,该指令将应用于整个请求,并且共享(代理服务器)缓存必须在满足请求之前强制使用原始Web服务器成功重新验证。使用字段名称,该指令仅适用于指定字段;其余的响应可以从共享缓存中提供。

  • 私人
      

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

  • 公共
      

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

  • 服务器
      

    指定仅在源服务器上缓存响应。与NoCache选项类似。客户端收到Cache-Control:no-cache指令,但文档缓存在源服务器上。相当于ServerAndNoCache。

  • ServerAndNoCache
      

    应用Server和NoCache的设置以指示内容在服务器上缓存,但所有其他内容都被明确拒绝缓存响应。

  • ServerAndPrivate
      

    表示响应缓存在服务器和客户端,但不在其他地方。不允许代理服务器缓存响应。

答案 1 :(得分:1)

NoCache: nobody can cache the page.
Private: only browsers can cache it (but not shared proxies). This is the default value
Public: everybody can cache the page, proxies included
Server: pages are cached only on the server (like the NoCache, so browsers don't cache the page)
ServerAndNoCache: pages are cached only on the server (like the NoCache, so browsers don't cache the page)
ServerAndPrivate: only browsers can cache it (but not shared proxies). 

您可以在这里阅读更多内容:

http://codeclimber.net.nz/archive/2007/04/01/Beware-the-ASP.NET-SetCacheability-method.aspx