Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I not set @OutputCache Shared Attribute in Webforms?

Reading the @OutputCache documentation in MSDN I have noticed the Shared attribute

Doc says:

Shared

A Boolean value that determines whether user control output can be

shared with multiple pages. The default is false. For more information, see the Remarks section.

Remarks says:

If you set the Shared attribute to true, cached user control output can be accessed by multiple Web Forms pages. If you do not set it to true, the default behavior is to cache one version of user control output for each page that contains that user control. You can potentially save a significant amount of memory by enabling the Shared attribute. For more information, see Caching Portions of an ASP.NET Page.

So I'm starting to believe that normally this should be set to true for controls that are gonna be rendered exactly in different pages in order to save cache memory.

The question is... when should I not set Shared to true?

like image 324
Carlos Muñoz Avatar asked Apr 10 '26 11:04

Carlos Muñoz


1 Answers

You should not use it when the control output is different across different pages.

Say you have a control whose output changes depending on how one navigates your site (breadcrumb control) - you do not want that to be shared across pages.

like image 63
Oded Avatar answered Apr 14 '26 00:04

Oded



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!