XmlDataSource.EnableCaching Propiedad

Definición

Obtiene o establece un valor que indica si el control XmlDataSource está habilitado.

public:
 virtual property bool EnableCaching { bool get(); void set(bool value); };
public virtual bool EnableCaching { get; set; }
member this.EnableCaching : bool with get, set
Public Overridable Property EnableCaching As Boolean

Valor de propiedad

Boolean

Es true si el almacenamiento de datos en caché está habilitado para el control de origen de datos; de lo contrario, es false. El valor predeterminado es true.

Ejemplos

En el ejemplo de código siguiente se muestra cómo habilitar el almacenamiento en caché al usar el XmlDataSource control para mostrar los datos contenidos en un archivo XML. El almacenamiento en caché se habilita cuando la EnableCaching propiedad se establece true en y CacheDuration se establece en el número de segundos en que el control de origen de datos almacena en caché los datos.

<%@ 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>
</head>
<body>

    <form id="form1" runat="server">
      <asp:xmldatasource
        id="XmlDataSource1"
        runat="server"
        datafile="books.xml"
        enablecaching="True"
        cacheduration="60"
        cacheexpirationpolicy="Sliding" />

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

      <asp:treeview
        id="TreeView1"
        runat="server"
        datasourceid="XmlDataSource1">
        <databindings>
          <asp:treenodebinding datamember="book" textfield="title"/>
        </databindings>
      </asp:treeview>

    </form>
  </body>
</html>
<%@ Page Language="VB" %>
<!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>
</head>
<body>
    <form id="form1" runat="server">

      <asp:xmldatasource
        id="XmlDataSource1"
        runat="server"
        datafile="books.xml"
        enablecaching="True"
        cacheduration="60"
        cacheexpirationPolicy="Sliding" />

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

      <asp:treeview
        id="TreeView1"
        runat="server"
        datasourceid="XmlDataSource1">
        <databindings>
          <asp:treenodebinding datamember="book" textfield="title"/>
        </databindings>
      </asp:treeview>

    </form>
  </body>
</html>

El archivo XML del ejemplo de código tiene los datos siguientes:

<books>  
   <computerbooks>  
     <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"/>                  
   </computerbooks>  
   <cookbooks>  
     <book title="Silicon Valley Gastronomic Treats" author="Innes del Castill"/>  
   </cookbooks>  
</books>  

Comentarios

El XmlDataSource control almacena automáticamente los datos en caché cuando la EnableCaching propiedad se establece trueen . De forma predeterminada, la CacheDuration propiedad se establece en 0, lo que indica una caché indefinida y el origen de datos almacenará en caché los datos hasta que se cambie el archivo XML del que depende. Si establece la CacheDuration propiedad en un valor mayor que 0, la memoria caché almacena los datos durante muchos segundos antes de recuperar un conjunto nuevo.

Si la EnableCaching propiedad se establece true en y la TransformArgumentList propiedad se establece, las entradas de caché no se invalidan automáticamente cuando los parámetros cambian en la lista de argumentos de transformaciones. En ese caso, debe escribir código para invalidar la memoria caché estableciendo la CacheKeyDependency propiedad .

Se aplica a

Consulte también