編集:(非ASP.NETMVCアプリの場合)
これはどう:
OutputCache定義を次のようにします。
<%@ OutputCache Duration="120" VaryByParam="None" VaryByCustom="listingtype;propertytype;location" %>
Global.asax.csに、次のメソッドを追加します。
public override string GetVaryByCustomString(HttpContext context, string custom)
{
if (custom == "lisingtype")
{
return GetParamFromRouteData("listingtype", context);
}
if (custom == "propertytype")
{
return GetParamFromRouteData("propertytype", context);
}
if (custom == "location")
{
return GetParamFromRouteData("location", context);
}
return base.GetVaryByCustomString(context, custom);
}
private string GetParamFromRouteData(string routeDataKey, HttpContext context)
{
object value;
if (!context.Request.RequestContext.RouteData.Values.TryGetValue(routeDataKey, out value))
{
return null;
}
return value.ToString();
}
古いコンテンツ:
単にOutputCacheをアクションメソッドに配置し、すべてのルート部分をアクションメソッドの一部にすると、次のようになります。
[OutputCache]
public ActionResult FindProperties(string listingtype, string propertytype, string location)
{
}
フレームワークは、これらのアイテムによってキャッシュを自動的に変更します(http://aspalliance.com/2035_Announcing_ASPNET_MVC_3_Release_Candidate_2_.4を参照) 。