Caching in asp.net-mvc

I like to cache in the model or data layer as well. This isolates everything to do with retrieving data from the controller/presentation. You can access the ASP.NET cache from System.Web.HttpContext.Current.Cache or use the Caching Application Block from the Enterprise Library. Create your key for the cached data from the parameters for the query. Be sure to invalidate the cache when you update the data.


Or you can be independent of the HttpContext.Current and access Cache from HttpRuntime.Cache :)


Often, OutputCaching can be the most fast and efficient, but only when it meets your requirements. No point in having fast efficient if it's wrong! ;)

In this case, it sounds like caching at the data layer is correct because you have complex caching needs. Sometimes, you can combine the two if the set of parameters which control what output is cached is simple.