First you have to change your [OutputCache]
to include VaryByParam=""
:
[OutputCache(Duration = CACHE_DURATION, VaryByCustom = "$LanguageCode;myParam", VaryByParam = "", Location = OutputCacheLocation.Server)]
Becuase by default its value is "*"
(All).
Then in your GetVaryByCustomString()
method, try to return your generated string instead of calling the base method:
return res.ToString();
Here's the source code of the base.GetVaryByCustomString()
method:
public virtual string GetVaryByCustomString(HttpContext context, string custom) {
if (StringUtil.EqualsIgnoreCase(custom, "browser")) {
return context.Request.Browser.Type;
}
return null;
}
As you can see, it doesn't do what you think it does, it only compares the Browser type with the string you provided and if there's no match it returns null
, not the string
you provided.
(I suspect the [OutputCache]
change alone will suffice, but try changing the method as well)