You can change the output caching based on almost everything you want using VaryByCustom and providing a special function that will return a cache key string. For your case, try this directive:
<%@ OutputCache Duration="30" VaryByParam="myParam" VaryByCustom="mySessionVar" %>
Then in Global.asax redefine the GetVaryByCustomString function for your application:
public override string GetVaryByCustomString(HttpContext context, string arg)
{
if(arg == "mySessionVar" && Session["mySessionVar"] != null)
{
return Session["mySessionVar"].ToString();
}
return base.GetVaryByCustomString(context, arg);
}
source
share