Vinay Kumar Chella
Vinay Kumar Chella

Reputation: 1729

Can I Implement Caching in MVC, If so how?

Can I Implement Caching in MVC, If so how? I wanted to implement Cache in Controllers

Upvotes: 5

Views: 1021

Answers (3)

Brendan Enrick
Brendan Enrick

Reputation: 4297

If you're going to be implementing caching, you will most likely want to use something more advanced than simple output caching. Usually it is best to simply cache the data that you're using to load the view.

You want to make it so that your controllers get cached data when they try to get the data they need for the view.

If you know and use repositories to get your data, you can implement a CachedRepository, which will make it so that when you access your data, you will get the cached version if it's been retrieved once already.

This is a great post by Steve Smith on the CachedRepository Pattern.

Upvotes: 0

Amitabh
Amitabh

Reputation: 61187

Simplest way to do that in controller is

[OutputCache(Duration = 10, VaryByParam = "none")]
public ActionResult Index()
  {
     return View();
  }

Upvotes: 6

Branislav Abadjimarinov
Branislav Abadjimarinov

Reputation: 5131

You can use the asp.net caching mechanisms - http://msdn.microsoft.com/en-us/library/xsbfdd8c%28VS.9%29.aspx

Upvotes: 1

Related Questions