Frage

Asp.net Is it possible/bad idea to store server controls in the cache?

Is it a bad idea to create a control ie: HtmlGenericControl and then add it to the Page.Cache and then retrieve it on OnInit() and add it to the pages controls collection?

Or is it better to use ParseControl?

War es hilfreich?

Lösung

It is rather dangerous. Every time the page is invoked you get an instance of it. This instance will have the instances of all controls the designer put in. If you store the instance of the control in the cache you may get into a situation where multiple instances of a page will share the instance of the control. You need to be careful what goes into this control data portion because it will be also shared

Andere Tipps

Since a Control is specific to a Page (e.g. has a Page property), you can't store it in Cache and share it between multiple pages. Maybe you might look at fragment caching instead.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top