Given an outputcache directive like this on a page
<%@ OutputCache Duration="3600" VaryByParam="Id" %>
How can I tell what the VaryByParam value is in code.
The HttpContext.Current.Response.Cache.VaryByParams object contains a private _parameters Dictionary and an internal IsVaryByStar property, but without reflecting into the object which I’m fairly loath to do, I can’t access them. Is there any standard way to discover what outputcache directives have been set on a particular request?
I don’t believe that there would be another way to enumerate parameters. Beside enumerating parameters, you may have to look out for wild-card(
"*") parameter. So I believe that the simplest way would be to use reflection.On different note, I am not certain about exact use case that needs such requirement. Couple of alternative approaches may or may not suite you requirements are
Response.Cache.Itemwill return true for all parameters). Possible alternative is to force page to give its cache parameters by introducing an abstract method from base page class.