DataSourceCacheExpiry Enum

Definition

Describes the way data cached using ASP.NET caching mechanisms expires when a time-out is set.

public enum DataSourceCacheExpiry
Inheritance
DataSourceCacheExpiry

Fields

Name Value Description
Absolute 0

Cached data expires when the amount of time specified by the CacheDuration property has passed since the data was first cached.

Sliding 1

Cached data expires only when the cache entry has not been used for the amount of time specified by the CacheDuration property.

Examples

The following example demonstrates how to use the DataSourceCacheExpiry enumeration declaratively. In this example, a SqlDataSource control is used to display data in a GridView control. The 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>

Remarks

The DataSourceCacheExpiry enumeration describes how data cached by a data source control expires in the ASP.NET cache. 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. The DataSourceCacheExpiry describes how this time-out setting is used. 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. 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.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also