DataSourceCacheExpiry 枚举

定义

描述在设置超时时,使用 ASP.NET 缓存机制缓存的数据过期的方式。

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

字段

Absolute 0

自数据第一次缓存起经过了 CacheDuration 属性指定的时间量后,缓存数据会过期。

Sliding 1

仅当在 CacheDuration 属性指定的时间量内没有使用缓存项时,缓存数据才会过期。

示例

以下示例演示如何以声明方式使用 DataSourceCacheExpiry 枚举。 在此示例中, SqlDataSource 控件用于显示控件中的数据 GridView 。 控件 SqlDataSource 已启用缓存,并将其 CacheExpirationPolicy 设置为 Sliding ,以缓存数据(只要存在活动)。

<!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 缓存中过期。 ASP.NET 数据源控件根据指定的超时期限(使用 CacheDuration 属性设置)缓存 ASP.NET 缓存中的数据。 介绍了 DataSourceCacheExpiry 如何使用此超时设置。 如果过期策略设置为 Absolute,则当自首次缓存数据以来指定的时间过后,将丢弃缓存的数据。 如果过期策略设置为 Sliding,则仅当缓存条目未使用指定的时间量时,才会放弃缓存数据。

适用于

另请参阅