0

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?

2 Answers 2

5

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.

1

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.