System.Web.UI.WebControls.SqlDataSource.CacheDuration Property

Gets or sets the length of time, in seconds, that the data source control caches data that is retrieved by the SqlDataSource.Select(System.Web.UI.DataSourceSelectArguments) method.

Syntax

[System.ComponentModel.DefaultValue(0)]
public virtual int CacheDuration { set; get; }

Value

Documentation for this section has not yet been entered.

Remarks

The System.Web.UI.WebControls.SqlDataSource control supports data caching. While data is cached, the SqlDataSource.Select(System.Web.UI.DataSourceSelectArguments) method retrieves data from the cache rather than from the underlying database. When the cache expires, the SqlDataSource.Select(System.Web.UI.DataSourceSelectArguments) method retrieves data from the underlying database, and then caches the data again.

The System.Web.UI.WebControls.SqlDataSource control automatically caches data when the SqlDataSource.EnableCaching property is set to true and the SqlDataSource.CacheDuration property is set to a value greater than 0, which indicates the number of seconds that the cache stores data before the cache entry is discarded. A value of 0 indicates an infinitely long cache.

The behavior of the cache is determined by a combination of the duration and the SqlDataSource.CacheExpirationPolicy property. If the SqlDataSource.CacheExpirationPolicy property is set to the System.Web.UI.DataSourceCacheExpiry.Absolute value, the System.Web.UI.WebControls.SqlDataSource caches data on the first data retrieval operation, holds it in memory for, at most, the amount of time that is specified by SqlDataSource.CacheDuration property. The data might be released before the duration time, if the memory is required. The cache is then refreshed during the next operation. If the SqlDataSource.CacheExpirationPolicy property is set to the System.Web.UI.DataSourceCacheExpiry.Sliding value, the data source control caches data on the first data retrieval operation, but resets the time window that it holds the cache for each subsequent operation. The cache expires, if there is no activity for a time that is equal to the SqlDataSource.CacheDuration value since the last SqlDataSource.Select(System.Web.UI.DataSourceSelectArguments) operation.

The System.Web.UI.WebControls.SqlDataSource control can cache data only when it is in SqlDataSourceMode.DataSet mode. A NotSupportedException exception is thrown by the SqlDataSource.Select(System.Web.UI.DataSourceSelectArguments) method, if the System.Web.UI.WebControls.SqlDataSource control is set to the SqlDataSourceMode.DataReader value and caching is also enabled.

Note:

When you are using client impersonation under Microsoft Windows authentication, the data is cached when the first user accesses the data. If another user requests the same data, the data is retrieved from the cache. The data is not retrieved by making another call to the database to verify the user's access to the data. If you expect more than one user to access the data, and you want each retrieval to the data to be verified by the security configurations for the database, do not use caching.

Requirements

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0