Gets or sets a user-defined key dependency that is linked to all data cache objects that are created by the data source control.
Assembly: System.Web (in System.Web.dll)
The property can be set to any arbitrary string value.
All cache objects are explicitly expired when the key is expired. This allows you to invalidate cache entries that are created by the ObjectDataSource from your own page code programmatically.
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 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.
You can set the property to create a dependency between all cache entries that are created by the ObjectDataSource control and the key. You can expire all the cache entries programmatically at any time by expiring the key. Expire the key by using the Cache.Remove method with the current value as the parameter.
A unique cache entry is created for every combination of the CacheDuration, CacheExpirationPolicy, TypeName, SelectMethod, and SelectParameters properties. Multiple ObjectDataSource controls can use the same cache entries in scenarios where they load data using the same type, method, and parameters.
The following three examples show a Web page, a code-behind page class, and a data-access class that retrieve records from the Employees table in the Northwind database.
The first example shows a Web page that contains two ObjectDataSource controls, a DropDownList control, and a DetailsView control. The first ObjectDataSource control and the DropDownList control are used to retrieve and display employee names from the database. The second ObjectDataSource control and the DetailsView control are used to retrieve and display the employee record that is selected by the user.
Caching is enabled for the ObjectDataSource control. Therefore, each record is retrieved only one time from the database. The property is set to "EmployeeDetails", but any string value can work as the key. The Web page also includes a Button control that the user can click to expire the cached data.
The second example shows a handler for the Load event and a handler for the Click event of the Button control. The Load event handler creates a cache item with a key set to the value. The Click event handler removes the cache item whose key is equal to the value. When the cache item is removed, all the cached data that is dependent on the key is expired.
The third example shows the data access class that interacts with the Northwind database. The class uses LINQ to query the Employees table. The example requires a LINQ to SQL class that represents the Northwind database and the Employees table. For more information, see How to: Create LINQ to SQL Classes in a Web Project.
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)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.