您可以使用基于控制器操作的参数在asp.net MVC的输出缓存 [英] can you use output caching in asp.net-mvc based on the parameters of your controller action

查看:98
本文介绍了您可以使用基于控制器操作的参数在asp.net MVC的输出缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用输出缓存,以避免撞到我的分贝一遍又一遍用相同的静态查询,但我的控制器有唯一确定后的参数。

i want to use output caching to avoid hitting my db over and over with the same static query but my controllers have parameters that uniquely define the post.

如何能影响我的参数,还支持在asp.net MVC的输出缓存?

How can i factor in my parameters and still support output caching in asp.net-mvc?

推荐答案

检查出的OutputCache属性的Var​​yByParam属性。

Check out the VaryByParam property of the OutputCache attribute.

[OutputCache(Duration=int.MaxValue, VaryByParam="id")]
public ActionResult Details(int id)
{
}

有关价值每一个独特的ID,独特的缓存实例将被创建。

For each unique id value, a unique cache instance will be created.

编辑:

如果您需要缓存超越简单的VaryByParam场景再看看VaryByCustom是。这将允许您设置的场景,你认为合适(用于记录在主场迎战缓存版本未登录的用户,等等等等。)

If your caching needs go beyond simple VaryByParam scenarios then take a look at VaryByCustom. This will allow you to setup the scenarios as you see fit (cached version for logged in vs. not logged in user, etc. etc.)

这篇关于您可以使用基于控制器操作的参数在asp.net MVC的输出缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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