开发者

Can you in code find out what OutputCache VaryByParams values have been set on a page/control in .NET?

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开发者_Python百科 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

  1. Build your own control/extender to accept caching parameters (instead of OutputCache directive) and then modify Response.Cache in early page life cycle.
  2. Use brute-force attack by building dictionary of all possible parameters (but wild-card support may spoil this because in such case Response.Cache.Item will 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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜