开发者

Asp.net MVC Output cache

开发者 https://www.devze.com 2023-02-15 09:56 出处:网络
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

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

精彩评论

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