XmlDataSource.CacheExpirationPolicy Propriedade

Definição

Obtém ou define a política de expiração de cache que é combinada com a duração do cache para descrever o comportamento do cache que o controle de fonte de dados usa.Gets or sets the cache expiration policy that is combined with the cache duration to describe the caching behavior of the cache that the data source control uses.

public:
 virtual property System::Web::UI::DataSourceCacheExpiry CacheExpirationPolicy { System::Web::UI::DataSourceCacheExpiry get(); void set(System::Web::UI::DataSourceCacheExpiry value); };
public virtual System.Web.UI.DataSourceCacheExpiry CacheExpirationPolicy { get; set; }
member this.CacheExpirationPolicy : System.Web.UI.DataSourceCacheExpiry with get, set
Public Overridable Property CacheExpirationPolicy As DataSourceCacheExpiry

Valor da propriedade

DataSourceCacheExpiry

Um dos valores de DataSourceCacheExpiry.One of the DataSourceCacheExpiry values. A configuração de política de expiração de cache padrão é Absolute .The default cache expiration policy setting is Absolute.

Exemplos

O exemplo de código a seguir demonstra como habilitar o Caching ao usar o XmlDataSource controle para exibir dados contidos em um arquivo XML.The following code example demonstrates how to enable caching when using the XmlDataSource control to display data contained in an XML file. O Caching é habilitado quando a EnableCaching propriedade é definida como true e o CacheDuration é definido como o número de segundos em que os dados são armazenados em cache pelo controle da fonte de dados.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>
</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:The XML file in the code example has the following data:

<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 comportamento do cache é regido por uma combinação das CacheDuration CacheExpirationPolicy configurações e.The behavior of the cache is governed by a combination of the CacheDuration and CacheExpirationPolicy settings. Se o CacheExpirationPolicy for definido como Absolute , o XmlDataSource armazenará em cache os dados na primeira operação de recuperação de dados, os manterá na memória pelo período de tempo especificado pelo CacheDuration e os invalidará depois que o tempo tiver se passado.If the CacheExpirationPolicy is set to Absolute, the XmlDataSource caches data on the first data retrieval operation, holds it in memory for the amount of time specified by CacheDuration, and invalidates it after the time has lapsed. O cache é então atualizado na próxima operação.The cache is then refreshed upon the next operation. Se o CacheExpirationPolicy for definido como Sliding , o controle da fonte de dados armazenará em cache os dados na primeira operação de recuperação de dados, mas redefinirá a janela de tempo em que ele armazena o cache em cada operação subsequente.If the CacheExpirationPolicy is set to Sliding, the data source control caches data on the first data retrieval operation, but resets the time window that it holds the cache for upon each subsequent operation. O cache irá expirar somente se não houver atividade por um tempo igual ao CacheDuration desde a última recuperação de dados.The cache will expire only if there is no activity for a time equal to the CacheDuration since the last data retrieval.

Aplica-se a

Confira também