Session と OutputCache に Couchbase を使用しています。
このコンテキストでは、セッションから値を取得するカスタム モデル バインダーを使用して、メソッドに渡される複雑なオブジェクトをキャッシュするにはどうすればよいでしょうか?
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
これは、オブジェクトがセッションから取得される方法です。
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
か?