How to verify ASP.NET MVC OutputCache works on server?
Asked Answered
S

1

9

I'm fixing a bug with ASP.NET OutputCache and it's driving me insane. We want caching on the server, but it does not appear to work (it did a while ago, in an older version of our app, but we discovered the bug by accident recently).

Locally, I just cannot get the caching to work on the server-side. Using this attribute:

[OutputCache(CacheProfile = "MyProfile", Location = OutputCacheLocation.Server)] // doesn't work

Now, based on a few things I've read by googling around, here is possibly relevant information:

  • Output caching is enabled in IIS (localhost)
  • I DO use an AuthorizeAttribute (a custom one with inheritance). I've debugged towards this specifically, and I'm 95% confident this is not the cause.
  • I've fiddled around with various VaryByParams values, nothing works.
  • Caching does work client-side.

I've opened a perfmon session and added some counters from the Web Service Cache group, All I see is that there are cached URL's but the cache is missed:

perfmon graph

The bigger problem/bug we're facing now is that OutputCache is not working at all right now. We were able to fix that by specifying VaryByParams="" (an empty string). That did it for the client. But it doesn't work server-side yet.

I'm actually checking whether it works or not by placing a debug breakpoint in the action that should be cached. It gets hit everytime, which should mean the cache is not hit.

Sateen answered 15/10, 2015 at 10:21 Comment(4)
I had a similar issue and it was a problem with the cache profiles. If I didn't use a cache profile and instead plugged the values directly into the attributes contructor it worked. Have you tried that?Shriek
@Shriek I tried it, and it doesn't make a difference.Sateen
@MarioDS:I'm running into the same problem. Did you manage to solve this?Function
@Function Not that I remember. I guess we moved on to more important issues.Sateen
O
0

From http://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/improving-performance-with-output-caching-cs:

There is no guarantee that content will be cached for the amount of time that you specify. When memory resources become low, the cache starts evicting content automatically.

If the available memory resources on your server are low enough during your testing, the cache will evict content immediately. I'm sure it could even refuse to put your content in the cache.

Obstreperous answered 31/10, 2015 at 12:27 Comment(1)
Thanks for providing one reason, but that is not it in our case.Sateen

© 2022 - 2024 — McMap. All rights reserved.