views:

13

answers:

0

Hi, I've come across hints about output caching a server control, but have yet to find a definitive answer to: Can the output of a server control be cached (in the same way that user controls are cached)?

The suggestions I've come across involve caching the data (not true output caching), or suggest setting the response.cache options. Ideally, I'd like to be able to drag a server control on to the page and set properties with the same names as the outputcache directive:

Example:

<cc1:MyCustomControl ID="ctl1" runat="server" CacheDuration="200" VaryByCustom="user" />

I was going to dig into the framework to see how output caching really works, but was hoping to find some information to get me started. From my limited understanding, the parser decides whether or not a page/usercontrol is cached. Since server controls are not parsed, there would be no way to stop the code from executing. I suppose I could initialize an "IsInCache" boolean and make sure that all methods check that var before executing the code. This would not entirely eliminate the server control from being executed, but it might improve performance enough by avoiding calls to the database and binding data to controls.

I'm still using .NET 3.5, and haven't had much time to explore the OutputCache provider model in .NET 4.0. Maybe there's a solution in the latest version of the framework?

Any thoughts?