0
votes

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

1
Show more of the config, maybe the section is in the wrong place? - Daniel Stackenland
I just add a printscreen of my web.config file - Rémy
I don't know how fast you are testing, but in your image the duration is set to 60 (=1minute) - Daniel Stackenland

1 Answers

0
votes

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"/>