【问题标题】:How to set ASP.NET outputcache attribute in order to produce private and public caching?如何设置 ASP.NET outputcache 属性以产生私有和公共缓存?
【发布时间】:2014-01-25 15:48:21
【问题描述】:

我有一个无缝运行的 MVC 应用程序。现在我想稍微改进一下缓存。我试图使用 System.Web.Mvc 命名空间中的 OutputCache 属性,但无论我选择哪个值,标头始终是公共的或私有的。是否可以使用此属性将缓存设置为 private AND public

【问题讨论】:

  • 嗨,你的意思是在同一个请求中有一个公共和私有的缓存头吗?

标签: c# asp.net asp.net-mvc caching outputcache


【解决方案1】:

无法将输出缓存设置为私有和公共。

例如,深入研究 Page.cs 的源代码,我们发现以下内容。请注意,这两个选项都没有“可缓存性”选项,它们被实现为彼此的替代方案。

  switch (outputCacheLocation)
  {
    case OutputCacheLocation.Any:
      cacheability = HttpCacheability.Public;
      break;
    case OutputCacheLocation.Client:
      cacheability = HttpCacheability.Private;
      break;
    case OutputCacheLocation.Downstream:
      cacheability = HttpCacheability.Public;
      cache.SetNoServerCaching();
      break;
    case OutputCacheLocation.Server:
      cacheability = HttpCacheability.Server;
      break;
    case OutputCacheLocation.None:
      cacheability = HttpCacheability.NoCache;
      break;
    case OutputCacheLocation.ServerAndClient:
      cacheability = HttpCacheability.ServerAndPrivate;
      break;
    default:
      throw new ArgumentOutOfRangeException("cacheSettings", System.Web.SR.GetString("Invalid_cache_settings_location"));
  }

您可以在此处阅读更多关于 HttpCacheability 枚举的信息 http://msdn.microsoft.com/en-us/library/system.web.httpcacheability(v=vs.110).aspx

NB 这样做对我来说甚至没有意义,但我可能会遗漏一些东西。

【讨论】:

    猜你喜欢
    • 2015-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多