DataSourceCacheExpiry DataSourceCacheExpiry DataSourceCacheExpiry DataSourceCacheExpiry Enum

定义

描述在设置超时时,使用 ASP.NET 缓存机制缓存的数据过期的方式。Describes the way data cached using ASP.NET caching mechanisms expires when a time-out is set.

public enum class DataSourceCacheExpiry
public enum DataSourceCacheExpiry
type DataSourceCacheExpiry = 
Public Enum DataSourceCacheExpiry
继承
DataSourceCacheExpiryDataSourceCacheExpiryDataSourceCacheExpiryDataSourceCacheExpiry

字段

Absolute Absolute Absolute Absolute 0

自数据第一次缓存起经过了 CacheDuration 属性指定的时间量后,缓存数据会过期。Cached data expires when the amount of time specified by the CacheDuration property has passed since the data was first cached.

Sliding Sliding Sliding Sliding 1

仅当在 CacheDuration 属性指定的时间量内没有使用缓存项时,缓存数据才会过期。Cached data expires only when the cache entry has not been used for the amount of time specified by the CacheDuration property.

示例

下面的示例演示如何以声明方式DataSourceCacheExpiry使用枚举。The following example demonstrates how to use the DataSourceCacheExpiry enumeration declaratively. 在此示例中, SqlDataSource控件用于GridView在控件中显示数据。In this example, a SqlDataSource control is used to display data in a GridView control. 控件已启用缓存并将其CacheExpirationPolicy设置为Sliding , 只要有活动, 就会缓存数据。 SqlDataSourceThe SqlDataSource control has caching enabled and its CacheExpirationPolicy set to Sliding to cache data as long as there is activity.

<!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:SqlDataSource
                id="SqlDataSource1"
                runat="server"
                DataSourceMode="DataSet"
                ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
                EnableCaching="True"
                CacheDuration="20"
                CacheExpirationPolicy="Sliding"
                SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees">
            </asp:SqlDataSource>

            <asp:GridView
                id="GridView1"
                runat="server"
                AutoGenerateColumns="False"
                DataSourceID="SqlDataSource1">
                <columns>
                    <asp:BoundField HeaderText="First Name" DataField="FirstName" />
                    <asp:BoundField HeaderText="Last Name" DataField="LastName" />
                    <asp:BoundField HeaderText="Title" DataField="Title" />
                </columns>
            </asp:GridView>

        </form>
    </body>
</html>
<!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:SqlDataSource
                id="SqlDataSource1"
                runat="server"
                DataSourceMode="DataSet"
                ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
                EnableCaching="True"
                CacheDuration="20"
                CacheExpirationPolicy="Sliding"
                SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees">
            </asp:SqlDataSource>

            <asp:GridView
                id="GridView1"
                runat="server"
                AutoGenerateColumns="False"
                DataSourceID="SqlDataSource1">
                <columns>
                    <asp:BoundField HeaderText="First Name" DataField="FirstName" />
                    <asp:BoundField HeaderText="Last Name" DataField="LastName" />
                    <asp:BoundField HeaderText="Title" DataField="Title" />
                </columns>
            </asp:GridView>

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

注解

DataSourceCacheExpiry枚举描述数据源控件缓存的数据在 ASP.NET 缓存中的过期时间。The DataSourceCacheExpiry enumeration describes how data cached by a data source control expires in the ASP.NET cache. ASP.NET 数据源控件基于指定的超时期限 (使用CacheDuration属性设置) 来缓存 ASP.NET 缓存中的数据。An ASP.NET data source control caches data in the ASP.NET cache based on a specified time-out period, which is set using the CacheDuration property. DataSourceCacheExpiry描述如何使用此超时设置。The DataSourceCacheExpiry describes how this time-out setting is used. 如果将过期策略设置为Absolute, 则在第一次缓存数据以来指定的时间量会丢弃缓存的数据。If the expiration policy is set to Absolute, the cached data is discarded when the amount of time specified passes since the data was first cached. 如果将过期策略设置为Sliding, 则只有在指定的时间量内未使用缓存项时, 才会丢弃缓存的数据。If the expiration policy is set to Sliding, the cached data is discarded only when the cache entry has not been used for the amount of time specified.

适用于

另请参阅