3

Problem: I've got an ASP.NET website and i don't believe that my code is getting OutputCached correctly. I'm using IIS7 performance counters to show me the hits or misses a second.


i've got a simple ASP.NET MVC website. I'm using the built in ASP.NET Output Cache magic.

Here's some sample code :-

[AcceptVerbs(HttpVerbs.Get)]
[ApiAuthorize]  // <-- this checks the querystring for a "key=1234". 
                // Doesn't find it, then it throws a 401 NOT AUTH exception.
[OutputCache(CacheProfile = "HomeController_Foo")]
public ActionResult Foo(string name, byte? alpha, byte? beta)
{
}

so this means that each url query can be like the following :-

Now, notice how i've got the OutputCache referencing a config file? here it is...

<caching>
    <outputCacheSettings>
        <outputCacheProfiles>
            <add name="HomeController_Foo" duration="3600" varyByParam="key;name;alpha;beta"/>
        </outputCacheProfiles>
    </outputCacheSettings>
</caching>

Nothing too hard ...

so here's the kicker! When I confirm that this is happening by using the IIS7 performance counters, it's saying that the output cache misses/sec are 100% of the requests i'm making a sec. Output cache hits are 0/sec.

I'm using a 3rd party web load stress testing program to bast my site with queries. Now, what's the source data? a list of names. The program keeps looping through all the names, then goes back to the start, rinse repeat. So it's BOUND to call the same query string at least once. IIS log files confirm this.

I'm not passing in any data for the alpha or beta.

this is my query string i'm hitting....

... where i keep substituting the 'hello+world' with the names from the data source file and IIS logs confirm this.

So .. am i looking at the wrong performance counter? Are there any other tricks to see if it's getting outputcached? The code is very fast, so it's hard to tell if that is a cached result or not.

Pure.Krome
  • 84,693
  • 113
  • 396
  • 647

2 Answers2

7

Probably way too late but to help others : If you had a cookie in your response header, that will prevent it from being cached. The outputcache (http) module has a lot of silent check to ensure the response is subject to being cached. Looking into it through reflection might give anyone candidate of failure to put in cache.

1

Use a tool like firebug and look at the response from the request. You'll be able to tell by the 200 or 304 whether the cache response was used (304) or if a successful response was sent (200).

Jarrett Meyer
  • 19,333
  • 6
  • 58
  • 52
  • I know I can use firebug, but i thought I the performance counters I mentioned might be applicable and report hits/misses? yes no? – Pure.Krome Oct 04 '09 at 13:26