Rémy
Rémy

Reputation: 908

ASP.NET MVC4 OutputCache with CacheProfile

I don't understand something about OutputCache.

Here are my tests

I have a simple Action which return the current time

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

In this case, it works perfectly.

Now I want to use cacheProfile Here is the action updated

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

and here is the web.config caching section

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

But when I test it doesn't work. If I call /MyController/hour?id=1 and /MyController/hour?id=2 I receive two different results although I set varyByParam="none" ;

And finally, I made another test

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

And for this case it works perfectly.

What does it mean? Why my VaryByParm property is not used from web.config file? Can somebody explain me?

Regards

Update 1: here is a printscreen of my web.config web.config

Upvotes: 0

Views: 754

Answers (1)

Daniel Stackenland
Daniel Stackenland

Reputation: 3239

In the image of your web.config the duration is set to 60 (=1 minute) not 3600 as stated in your question.

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

Upvotes: 0

Related Questions