缓存在asp.net-MVC [英] Caching in asp.net-mvc

查看:145
本文介绍了缓存在asp.net-MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想缓存在我的asp.net MVC的网站我最沉重的数据库操作。
在我的研究,我发现

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.

但我不觉得我得到它。

我希望能够缓存取决于几个标准杆我POST请求。这些标准杆是在一个对象。所以,我想缓存以下请求的结果是:

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)

在哪里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.

我有一种感觉,我应该在我的数据层高速缓存,而不是对我的行为。

我怎么使用的VaryByParam中的OutputCache属性?

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?

推荐答案

我喜欢在模型或数据层缓存。这株一切都与从控制器/ presentation检索数据。您可以从 System.Web.HttpContext.Current.Cache ASP.NET缓存或从企业库使用缓存应用程序块。从该查询的参数缓存的数据创建密钥。请务必在更新数据缓存失效。

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.

这篇关于缓存在asp.net-MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆