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

查看:31
本文介绍了在 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

  • 甜甜圈缓存在 Phil 的博客上
  • 缓存/压缩 Kazi 博客上的过滤器
  • Scott Hansleman 关于他们如何在 SO 中缓存内容的播客.
  • 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.

我觉得我应该缓存在我的数据层上,而不是我的动作上.
我应该如何在 OutputCache 属性中使用 VaryByParam?

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?

推荐答案

我也喜欢缓存在模型层或数据层.这隔离了与从控制器/演示文稿检索数据有关的一切.您可以从 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天全站免登陆