Gets or sets the length of time, in seconds, that the data source control caches data that is retrieved by the SelectMethod property.
Assembly: System.Web (in System.Web.dll)
[<TypeConverterAttribute(typeof(DataSourceCacheDurationConverter))>] abstract CacheDuration : int with get, set [<TypeConverterAttribute(typeof(DataSourceCacheDurationConverter))>] override CacheDuration : int with get, set
The ObjectDataSource control supports data caching. While data is cached, calls to the Select method retrieve data from the cache rather than from the business object that the ObjectDataSource works with. When the cache expires, the Select method retrieves data from the business object, and then caches the data again.
The ObjectDataSource control automatically caches data when the EnableCaching property is set to true and the 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 cache is regulated by a combination of the duration and the CacheExpirationPolicy setting. If the CacheExpirationPolicy property is set to the Absolute value, the ObjectDataSource caches data on the first call to the Select method and holds it in memory for, at most, the amount of time that is specified by the property. The data might be released before the duration time, if the memory is needed. The cache is then refreshed during the next call to the Select method. If the CacheExpirationPolicy property is set to Sliding value, the data source control caches data on the first call to the Select method, but resets the time window for which it holds the cache on each subsequent call to the Select method. The cache expires if there is no activity for a time that is equal to the property since the last call to the Select method.
This section contains two code examples. The first code example demonstrates how an ObjectDataSource object supports caching. The second code example demonstrates how to implement a wrapper method that returns a DataSet object to enable caching with an ObjectDataSource object.
The following code example demonstrates how an ObjectDataSource control supports caching. To enable caching, you must implement the method that retrieves data, which is identified by the SelectMethod property, to return the data as a DataSet object. In this example, the EnableCaching property is set to true, and the and CacheExpirationPolicy properties are set. The ObjectDataSource caches data that is returned by the SelectMethod property for 30 seconds.
The following code example demonstrates how to implement a wrapper method that returns a DataSet object to enable caching with an ObjectDataSource control. In the base implementation of the EmployeeLogic class, the GetAllEmployees method returns an ArrayList object. Instead of refactoring the object completely to work with the ObjectDataSource on a Web Forms page, a wrapper method named GetAllEmployeesAsDataSet is added that returns a set of NorthwindEmployee data as a DataSet.
This code example is part of a larger example provided for the ObjectDataSource class.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)