我们将 Couchbase 用于 Session 和 OutputCache。
在这种情况下,我们如何使用从 Session 中检索值的自定义模型绑定器通过传递给方法的复杂对象进行缓存?
这是我想用OutputCache
属性缓存的方法的签名:
[HttpGet]
[OutputCache(CacheProfile = "MyObjectsCache", VaryByParam = "myParam")]
public ActionResult Index([ModelBinder(typeof (CustomVariableSessionModelBinder<MyClass>))] MyClass myParam)
{
注意:这里使用 ModelBinder 的原因超出了我的范围,我无法更改它。
MyClass 是一个具有 Id 的复杂对象。我想使用 Id 作为缓存标识符。
public class MyClass
{
public int Id{get;set;}
//Other Properties
这是从 Session 中检索对象的方式:
var sessionKey = typeof (MyNamespace.MyClass).FullName;
var httpContext = HttpContext.Current;
MyNamespace.MyClass newObject = null;
if (httpContext.Session != null)
{
newObject = httpContext.Session[sessionKey] as MyNamespace.MyClass;
}
是否可以VaryByParam
用于这种情况或我必须使用VaryByCustom
?