Export (0) Print
Expand All

XmlDataSource.EnableCaching Property

Gets or sets a value indicating whether the XmlDataSource control has data caching enabled.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public virtual bool EnableCaching { get; set; }
<asp:XmlDataSource EnableCaching="True|False" />

Property Value

Type: System.Boolean
true if data caching is enabled for the data source control; otherwise, false. The default value is true.

The XmlDataSource control automatically caches data when the EnableCaching property is set to true. By default, the CacheDuration property is set to 0, which indicates an indefinite cache, and the data source will cache data until the XML file that it depends on is changed. If you set the CacheDuration property to a value greater than 0, the cache stores data for that many seconds before retrieving a fresh set.

If the EnableCaching property is set to true and the TransformArgumentList property is set, the cache entries are not automatically invalidated when the parameters change in the transforms argument list. In that case, you must write code to invalidate the cache by setting the CacheKeyDependency property.

The following code example demonstrates how to enable caching when using the XmlDataSource control to display data contained in an XML file. Caching is enabled when the EnableCaching property is set to true and the CacheDuration is set to the number of seconds that the data is cached by the data source control.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>

    <form id="form1" runat="server">
        cacheexpirationpolicy="Sliding" />

      <!- TreeView uses hierachical data, so the
          XmlDataSource uses an XmlHierarchicalDataSourceView
          when a TreeView is bound to it. -->

          <asp:treenodebinding datamember="book" textfield="title"/>


The XML file in the code example has the following data:

     <book title="Secrets of Silicon Valley" author="Sheryl Hunter"/>
     <book title="Straight Talk About Computers" author="Dean Straight"/>
     <book title="You Can Combat Computer Stress!" author="Marjorie Green"/>                
     <book title="Silicon Valley Gastronomic Treats" author="Innes del Castill"/>

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

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.

Community Additions

© 2015 Microsoft