Share via


XmlDataSource.EnableCaching Propriedade

Definição

Obtém ou define um valor que indica se o controle XmlDataSource tem o cache de dados 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 da propriedade

Boolean

true se o cache de dados estiver habilitado para o controle de fonte de dados; caso contrário, false. O valor padrão é true.

Exemplos

O exemplo de código a seguir demonstra como habilitar o cache ao usar o XmlDataSource controle para exibir dados contidos em um arquivo XML. Caching está habilitada quando a EnableCaching propriedade está definida true e o CacheDuration conjunto é definido como o número de segundos em que os dados são armazenados em cache pelo controle da fonte de dados.

<%@ 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>

O arquivo XML no exemplo de código tem os seguintes dados:

<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>  

Comentários

O XmlDataSource controle armazena automaticamente os dados em cache quando a EnableCaching propriedade é definida como true. Por padrão, a CacheDuration propriedade é definida como 0, o que indica um cache indefinido e a fonte de dados armazenará os dados em cache até que o arquivo XML do qual ele depende seja alterado. Se você definir a CacheDuration propriedade como um valor maior que 0, o cache armazenará dados por tantos segundos antes de recuperar um novo conjunto.

Se a EnableCaching propriedade estiver definida true e a TransformArgumentList propriedade estiver definida, as entradas de cache não serão invalidadas automaticamente quando os parâmetros forem alterados na lista de argumentos de transformações. Nesse caso, você deve escrever código para invalidar o cache definindo a CacheKeyDependency propriedade.

Aplica-se a

Confira também