开发者

Asp.net MVC Output cache

Im thinking in use the Output cache attribute for caching views in MVC.

My question is simple:

When i use output cache attribute on top of an action method, if in the nex开发者_JAVA百科t request the view was cached the action is not executed right?


Yes, you are correct. This is easliy tested:

[OutputCache(Duration=10, VaryByParam="id")]
public function TestCache()
{
    return Content(" I was generated at " + DateTime.Now);
}

However, you can invalidate the cache using the VaryByParam property, which allows you to control the cache depending on request parameters or similar.

In my example, the cache will vary depending on which id is specified in the request parameters. This is useful when you have a dynamic page which loads data from the database.


Yes you are right , the cached action is not executed unless you use varyByParam or some other property of that attribute.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜