[英]Have I to cache FindControl() result if I use it a number of times?
Does FindControl()
work quick or not? FindControl()
是否可以快速运行?
Have I to cache a result using a property like this or not if I search and use the same control a number of time? 如果我多次搜索并使用相同的控件,是否可以使用这样的属性来缓存结果?
private MyUserControl c;
private MyUserControl MyC
{
get
{
if(c == null)
c = (MyUserControl)FindControl("c");
return c;
}
}
If you're talking across requests then don't. 如果您正在处理多个请求,那就不要。 You can't in fact.
实际上你不能。 Control references only exist temporarily while the page is rende Putting them in session or some other persistent cache let's them persist and screws up the garbage collector
控件引用仅在页面被渲染时才临时存在。将它们放入会话或其他持久性缓存中,使其持久化并破坏垃圾收集器
every question with 'is it quick' should be answered: try it out. 回答“是否快速”的每个问题都应回答:尝试一下。
FindControl (i think) loops trough all the controls therefor the speed is depended on the amount of controls. FindControl(我认为)通过所有控件循环,因此速度取决于控件的数量。 I think you shouldn't worry.
我想你不用担心。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.