PartialCachingAttribute Class
Defines the metadata attribute that Web Forms user controls (.ascx files) use to indicate if and how their output is cached. This class cannot be inherited.
Assembly: System.Web (in System.Web.dll)
The PartialCachingAttribute type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | PartialCachingAttribute(Int32) | Initializes a new instance of the PartialCachingAttribute class with the specified duration assigned to the user control to be cached. |
![]() | PartialCachingAttribute(Int32, String, String, String) | Initializes a new instance of the PartialCachingAttribute class, specifying the caching duration, any GET and POST values, control names, and custom output caching requirements used to vary the cache. |
![]() | PartialCachingAttribute(Int32, String, String, String, Boolean) | Initializes a new instance of the PartialCachingAttribute class, specifying the caching duration, any GET and POST values, control names, custom output caching requirements used to vary the cache, and whether the user control output can be shared with multiple pages. |
![]() | PartialCachingAttribute(Int32, String, String, String, String, Boolean) | Initializes a new instance of the PartialCachingAttribute class, specifying the caching duration, any GET and POST values, control names, custom output caching requirements used to vary the cache, the database dependencies, and whether the user control output can be shared with multiple pages. |
| Name | Description | |
|---|---|---|
![]() | Duration | Gets the amount of time, in seconds, that cached items should remain in the output cache. |
![]() | ProviderName | Gets or sets the name of the provider that is used to store the output-cached data for the associated control. |
![]() | Shared | Gets a value indicating whether user control output can be shared with multiple pages. |
![]() | SqlDependency | Gets a delimited string that identifies one or more database and table name pairs that the cached user control is dependent on. |
![]() | TypeId | When implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.) |
![]() | VaryByControls | Gets a list of user control properties that the output cache uses to vary the user control. |
![]() | VaryByCustom | Gets a list of custom strings that the output cache will use to vary the user control. |
![]() | VaryByParams | Gets a list of query string or form POST parameters that the output cache will use to vary the user control. |
| Name | Description | |
|---|---|---|
![]() | Equals | Infrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Returns the hash code for this instance. (Inherited from Attribute.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | IsDefaultAttribute | When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.) |
![]() | Match | When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() ![]() | _Attribute::GetIDsOfNames | Maps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.) |
![]() ![]() | _Attribute::GetTypeInfo | Retrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.) |
![]() ![]() | _Attribute::GetTypeInfoCount | Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.) |
![]() ![]() | _Attribute::Invoke | Provides access to properties and methods exposed by an object. (Inherited from Attribute.) |
The PartialCachingAttribute attribute class marks user controls (.ascx files) that support fragment caching, and encapsulates the cache settings that ASP.NET uses when caching the control. Page and controls developers use the PartialCachingAttribute attribute to enable output caching for a user control in a code-behind file.
Using the PartialCachingAttribute is one of several ways you can enable output caching. The following list describes methods you can use to enable output caching.
Use the @ OutputCache directive to enable output caching in declarative scenarios.
Use the PartialCachingAttribute to enable caching for a user control in a code-behind file.
Use the ControlCachePolicy class to programmatically specify cache settings in programmatic scenarios in which you are working with BasePartialCachingControl instances.
If a user control contains an @ OutputCache directive or has a PartialCachingAttribute applied, the ASP.NET parser generates an instance of the PartialCachingControl class to wrap the user control.
For more information about ASP.NET caching, see ASP.NET Caching. For more information about using attributes, see Extending Metadata Using Attributes.
| Topic | Location |
|---|---|
| How to: Cache Multiple Versions of a User Control by Using Declarative Attributes | Building ASP .NET Web Applications |
| How to: Cache Multiple Versions of a User Control Based on Parameters | Building ASP .NET Web Applications |
| How to: Cache Multiple Versions of a User Control by Using Declarative Attributes | Building ASP .NET Web Applications |
| How to: Cache Multiple Versions of a User Control Based on Parameters | Building ASP .NET Web Applications |
| How to: Cache Multiple Versions of a User Control by Using Declarative Attributes | Building ASP .NET Web Applications in Visual Studio |
| How to: Cache Multiple Versions of a User Control by Using Declarative Attributes | Building ASP .NET Web Applications in Visual Studio |
The following code example demonstrates using the PartialCachingAttribute. This example has three parts:
A partial class, ctlMine, that inherits from the UserControl base class and to which the PartialCachingAttribute attribute is applied.
A user control that is used with the ctlMine partial class.
A Web Forms page that hosts the user control.
The first part of the example demonstrates a partial class that inherits from the UserControl base class and to which the PartialCachingAttribute attribute is applied. In this example, the attribute specifies that the user control should be cached for 20 seconds.
The second part of the example shows a user control that is used with the previous example to demonstrate user control caching.
The third part of the example demonstrates a Web Forms page that hosts the user control.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.




