0

I'm trying to implement a caching for some views and files on my MVC4 page (would like to chache on server and client). Looks easy but i dont get it why it doesnt work for me. I've tried this little example down here:

[OutputCache(Duration = 30000)]
public string Test()
{
  return DateTime.Now.ToLongTimeString();
}

Unfortunately the time of the result changes every second.. are there any settings in the webconfig or iis that must have been set? I didnt found anything about that but have no idea why even this little example doesnt work. Hope you can help me?

thanks in advance!

tereško
  • 58,060
  • 25
  • 98
  • 150
user1584028
  • 69
  • 1
  • 1
  • 4

2 Answers2

0

There wasn't enough information to decide either way, but it could be do to with parameters, you could try [OutputCache(Duration = 3600, VaryByParam = "none")]

or create a caching section and refeer to it by id

<caching>
<outputCacheSettings>
    <outputCacheProfiles>
        <add name="CacheExample" duration="3600" varyByParam="none"/>
    </outputCacheProfiles>
</outputCacheSettings>
</caching>

and then use

[OutputCache(CacheProfile="CacheExample")]
public string Test()
{
  return DateTime.Now.ToLongTimeString();
}
Steve
  • 3,673
  • 1
  • 19
  • 24
0

This should be working:

[OutputCache(Duration = 30000, Location = OutputCacheLocation.ServerAndClient,  VaryByParam="none")]
public string Test()
{
  return DateTime.Now.ToLongTimeString();
}
Alex Art.
  • 8,711
  • 3
  • 29
  • 47
  • I tried this very simple example but still i get after every refresh (Ctrl+R) a new time? – user1584028 Sep 23 '14 at 07:54
  • take a look on this question, maybe you have a similar issue: http://stackoverflow.com/questions/20027813/why-is-output-caching-not-working-for-my-asp-net-mvc-4-app – Alex Art. Sep 23 '14 at 08:03
  • thanks alex. There was a global filter which automatic set a cookie - that was my problem. – user1584028 Sep 23 '14 at 12:27