Caching in asp.net

I would like to cache my most database heavy actions in my asp.net-mvc site. In my research I have found

  • donut caching on Phil's blog
  • Caching/compressing filters on Kazi's blog
  • Scott Hansleman's podcast about how they cached things in SO.
  • But I don't feel I get it yet.
    I want to be able to cache my POST request depending on several pars. These pars are in an object. So I would like to cache the result of the following request:

    public ActionResult AdvancedSearch(SearchBag searchBag)
    

    Where searchBag is an object that holds (a bunch) of optional search parameters. My views themselves are light (as they should be), but the data access can be rather time consuming, depending on what fields are filled in in the search bag.

    I have the feeling I should be caching on my datalayer, rather then on my actions.
    How am I supposed to use the VaryByParam in the OutputCache attribute?


    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.


    或者您可以独立于HttpRuntime.Cache的HttpContext.Current和访问缓存:)


    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.

    链接地址: http://www.djcxy.com/p/55692.html

    上一篇: 禁用整个ASP.NET网站的浏览器缓存

    下一篇: 在asp.net中缓存