【问题标题】:ASP.NET MVC4 OutputCache with CacheProfile带有 CacheProfile 的 ASP.NET MVC4 OutputCache
【发布时间】:2018-04-23 11:21:26
【问题描述】:

我对 OutputCache 有一些不理解。

这是我的测试

我有一个返回当前时间的简单动作

[OutputCache(Duration = 3600, VaryByParam = "none", Location = System.Web.UI.OutputCacheLocation.Server)]
public string hour()
{
        return DateTime.Now.ToString("T");
}

在这种情况下,它可以完美运行。

现在我想使用 cacheProfile 这是更新的操作

[OutputCache(CacheProfile = "Cache1Hour")]
public string hour()
{
     return DateTime.Now.ToString("T");
 }

这里是 web.config 缓存部分

<caching>
  <outputCacheSettings>
    <outputCacheProfiles>
      <add name="Cache1Hour" duration="3600" varyByParam="none" location="Server"/>
    </outputCacheProfiles>
  </outputCacheSettings>
</caching>

但是当我测试时它不起作用。 如果我调用 /MyController/hour?id=1 和 /MyController/hour?id=2 我会收到两个不同的结果,尽管我设置了 varyByParam="none" ;

最后,我又做了一个测试

[OutputCache(CacheProfile = "Cache1Hour", VaryByParam ="none")]
public string hour()
{
    return DateTime.Now.ToString("T");
}

对于这种情况,它可以完美运行。

这是什么意思? 为什么我的 VaryByParm 属性没有从 web.config 文件中使用? 谁能解释一下?

问候

更新 1: 这是我的 web.config 的打印屏幕 web.config

【问题讨论】:

  • 显示更多配置,可能部分放错地方了?
  • 我只是添加了我的 web.config 文件的打印屏幕
  • 我不知道您的测试速度有多快,但在您的图片中,持续时间设置为 60(=1 分钟)

标签: asp.net-mvc asp.net-mvc-4 outputcache cacheprofile


【解决方案1】:

在您的 web.config 图像中,持续时间设置为 60(=1 分钟),而不是您问题中所述的 3600。

 <add name="Cache1Hour" duration="60" varyByParam="none" location="Server"/>

【讨论】:

  • 不,这不是问题
猜你喜欢
  • 1970-01-01
  • 2014-01-14
  • 2015-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-17
  • 1970-01-01
  • 2018-02-01
相关资源
最近更新 更多