Calling
http://foo/home/cachetest
for
[UrlRoute(Path = "home/cachetest")]
[OutputCache(Duration = 10, VaryByParam = "none")]
public ActionResult CacheTest()
{
return Content(DateTime.Now.ToString());
}
will show the same content for every 10 seconds no matter how often i refresh page.
Is it possible to easily add sliding expiration so it would NOT change after 10 seconds in case i have refreshed the page?
You can't. Internal timer of Cache class spins every 20 secs. I suggest you to try PCache class under PokeIn library. You can set down to 6 secs on it. Also, PCache far more faster in comparison to .NET cache class.
Been reading the source for the
OutputCacheAttribute
and I don't think there's an easy way to do this.You're most likely going to need to create your own solution.
You could create a custom cache filter instead of default OutputCache one. Like this below, note the sliding expiration could be set here. Caveat in that I have not used this for sliding expiration, but works well for other things.