Reputation: 9277
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 next request the view was cached the action is not executed right?
Upvotes: 0
Views: 1243
Reputation: 59022
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.
Upvotes: 5
Reputation: 4400
Yes you are right , the cached action is not executed unless you use varyByParam or some other property of that attribute.
Upvotes: 1