为什么不工作对我的ASP.NET MVC应用程序4输出缓存? [英] Why is output caching not working for my ASP.NET MVC 4 app?

查看:111
本文介绍了为什么不工作对我的ASP.NET MVC应用程序4输出缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有哪里输出缓存似乎没有被工作我的ASP.NET MVC 4(EPiServer 7)的网站的问题。

I am having an issue where output caching doesn't appear to be working for my ASP.NET MVC 4 (EPiServer 7) website.

我在 web.config中的以下输出缓存配置文件

<caching>
  <outputCacheSettings>
    <outputCacheProfiles>
      <add name="PageOutput" enabled="true" duration="300" varyByParam="*" location="ServerAndClient" />
    </outputCacheProfiles>
  </outputCacheSettings>
</caching>

这是我的静态资源输出缓存配置:

And here is my output caching configuration for static resources:

<caching>
  <profiles>
    <add extension=".gif" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
    <add extension=".png" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
    <add extension=".js" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
    <add extension=".css" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="00:01:00" location="Any" />
    <add extension=".jpg" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
    <add extension=".jpeg" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="00:01:00" location="Any" />
  </profiles>
</caching>

和我的控制器都装饰有像这样的输出缓存属性:

And my controller is decorated with an output cache attribute like so:

[OutputCache(CacheProfile = "PageOutput")]
public class HomePageController : BasePageController<HomePage>
{ ...}

我看性能监视器中的以下计数器,但没有看到他们的增量预期,当我访问主页:

I'm watching the following counters in perfmon but not seeing them increment as expected when I visit the home page:


  • \\ ASP.NET应用程序v4.0.30319(__ __总额)\\输出缓存条目

  • \\ ASP.NET应用程序v4.0.30319(__ __总额)\\输出缓存命中

  • \ASP.NET Apps v4.0.30319(__Total__)\Output Cache Entries
  • \ASP.NET Apps v4.0.30319(__Total__)\Output Cache Hits

我也一直在使用测试 tinyget 像这样:

I've also been testing using tinyget like so:

tinyget -srv:mywebsite -uri:/ -threads:1 -loop:20

任何意见将是极大的AP preciated!

Any advice would be greatly appreciated!

推荐答案

所以,事实证明,OutputCaching是工作,这只是我的测试它的方法是有缺陷的。如果响应不包括一个cookie的操作的结果将仅被缓存。当然,第一反应总是包括,如果你有ASP.NET会话启用,我们做一个cookie。因此,第一个响应头是这样的:

So, it turns out that OutputCaching was working, it was just that my method of testing it was flawed. The result of an action will only be cached if the response doesn't include a cookie. Of course the first response always includes a cookie if you have ASP.NET Session enabled which we do. Therefore the first response headers look like this:

HTTP/1.1 200 OK
Cache-Control: private, max-age=600
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Expires: Tue, 26 Nov 2013 03:48:44 GMT
Last-Modified: Tue, 26 Nov 2013 03:38:44 GMT
Vary: *
Set-Cookie: ASP.NET_SessionId=kbnhk4lphdlcpozcumpxilcd; path=/; HttpOnly
X-UA-Compatible: IE=Edge
Date: Tue, 26 Nov 2013 03:38:44 GMT
Content-Length: 9558

假设你的浏览器或测试工具可以接受饼干,包括那些在随后的请求,在同一个页面的下一个请求会导致像这样HTTP响应头:

Assuming your browser or test tool can accept cookies and include those in the subsequent requests, the next request to the same page would result in HTTP response headers like so:

HTTP/1.1 200 OK
Cache-Control: private, max-age=598
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Expires: Tue, 26 Nov 2013 03:48:45 GMT
Last-Modified: Tue, 26 Nov 2013 03:38:45 GMT
Vary: *
X-UA-Compatible: IE=Edge
Date: Tue, 26 Nov 2013 03:38:45 GMT
Content-Length: 9558

由于没有按预期的产量,现在可以缓存响应没有客户的具体信息。

As there is no client specific information in the response the output can now be cached as expected.

所以,教训是检测输出缓存使用测试工具,可以接受,并在随后的请求返回cookie时。

So, lesson is when testing output caching use a testing tool that can accept and return cookies in subsequent requests.

我们结束了使用的JMeter,而不是tinyget和现在一切都按预期工作。

We ended up using Jmeter rather than tinyget and everything now works as expected.

这篇关于为什么不工作对我的ASP.NET MVC应用程序4输出缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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