Caching in asp.net-mvc

I would like to cache the hardest database activities on my asp.net-mvc site. In my research, I found

But I don't feel like I'm still getting. I want to be able to cache my POST request depending on a few parses. These parses are in the object. Therefore, I would like to cache the result of the following query:

public ActionResult AdvancedSearch(SearchBag searchBag) 

Where searchBag is an object that contains (a bunch) of additional search parameters. My views themselves are easy (as it should be), but accessing the data can take quite a while, depending on which fields are filled in the search bag.

I have a feeling that I should cache on my datalayer, and not on my actions.
How should I use VaryByParam in the OutputCache attribute?

+81
caching asp.net-mvc
Dec 22 '08 at 10:51
source share
4 answers

I like to cache in the model or at the data level. This isolates everything that is needed to receive 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 corporate library. Create your key for cached data from query parameters. Be sure to cancel caching when updating data.

+73
Dec 23 '08 at 4:25
source share

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

+65
Feb 07 '09 at 2:24
source share

Often, OutputCaching can be the fastest and most effective, but only when it meets your requirements. It makes no sense to work quickly if it is wrong!;)

In this case, it looks like caching on the data layer is correct because you have complex caching. Sometimes you can combine these two if the set of parameters that control output caching is simple.

+11
Feb 07 '09 at 5:51
source share

you can use output caching something like this

 [OutputCache(Duration = 10, VaryByParam = "empID")] public ActionResult GetEmployeeDetail(int empID) { Employee e = new Employee(); return Content(e.getEmployeeDetails(empID)); } 

or you can use the cache profiles set in the web configuration

 <caching> <outputCacheSettings> <outputCacheProfiles> <add name="Admin" duration="86420" varyByParam="none"/> </outputCacheProfiles> </outputCacheSettings> </caching> and use this tag [OutputCache(CacheProfile="Admin")] 
0
Nov 21 '17 at 10:11
source share



All Articles