This documentation is archived and is not being maintained.

UserControl.CachePolicy Property

Gets a reference to a collection of caching parameters for this user control.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

public ControlCachePolicy CachePolicy { get; }
/** @property */
public ControlCachePolicy get_CachePolicy ()

public function get CachePolicy () : ControlCachePolicy

Not applicable.

Property Value

A ControlCachePolicy containing properties that define the caching parameters for this UserControl.

The CachePolicy property defines the cache parameters for the instance of the UserControl class. The CachePolicy property is read-only; however, you can set the properties of the ControlCachePolicy object that it returns.

The CachePolicy property can not be set declaratively. It must be set programmatically.

The following code example demonstrates how to use the SupportsCaching property to determine whether the user control can be cached, and if so, sets the Duration property to cache the control for 10 seconds.

<%@ page language="C#"%>
<%@ register src="SimpleControlcs.ascx" 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">
void Page_Init(object sender, EventArgs e)
  // If the control is already in the cache, calling properties
  // will throw an exception. Make sure the control is available. 
  if (SimpleControl1 != null)
    if (SimpleControl1.CachePolicy.SupportsCaching)
      // Set the cache duration to 10 seconds.
      SimpleControl1.CachePolicy.Duration = new TimeSpan(0, 0, 10);


Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0