O'Reilly logo

Programming ASP.NET, 3rd Edition by Dan Hurwitz, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Data Caching

Data caching is (surprise!) the caching of data from a data source. As long as the cache is not expired, a request for data will be fulfilled from the cache rather than the original data source. If the cache is expired, for whatever reason, then fresh data will be obtained by the data source and the cache will be refreshed. There are many reasons the cache can expire, as you will see. These can include time outs, changed data, or changes to other objects.

There are two kinds of data caching : DataSourceControl caching and SQL cache dependency . Both are very useful.

DataSourceControl Caching

Data source controls, covered in Chapter 9, represent data in a data source, such as a database or an XML file. The abstract DataSourceControl class has two controls derived from it: ObjectDataSource and SqlDataSource, from which AccessDataSource is derived. Each of these derived classes (though not the base class) has a number of properties for implementing caching, listed in Table 17-1.

Table 17-1. Data source control properties for caching

Property

Type

Get

Set

Description

CacheDuration

Integer

Length of time, in seconds, that data is cached before the cache is invalidated. The default value is Infinite.

CacheExpirationPolicy

DataSourceCacheExpiry

Default is Absolute. Other possible value is Sliding, in which case the countdown to cache expiration is reset every time the cache is accessed.

CacheKeyDependency

string

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required