DAO Recordset: Caching Multiple Records for Performance

HomeOverviewHow Do IFAQSampleTutorialODBC Driver List

This article discusses the mechanism by which you can use a configurable buffer to cache multiple records in a recordset.

Note   The recordset caching mechanism described here applies only to ODBC data sources. It has no effect or benefit with non-ODBC databases.

Topics covered include:

Normally, records are retrieved from the database one at a time. To improve the performance of operations such as seeking and scrolling in recordsets based on ODBC data sources, you can cause DAO to cache multiple records. When you request a record, the database engine looks for it first in the cache. If the record is not in the cache, the database engine gets the record from the server. This is marginally slower at the time the cache is filled, but faster for operations that navigate through the records later. Use of this mechanism is limited in several ways, however (besides its limitation to ODBC); see When Should You Use Record Caching?.

For an understanding of the DAO data caching mechanism that underlies MFC CDaoRecordset objects, see the following topics in DAO Help:

When Should You Use Record Caching?

Is record caching right for your application? This depends on several factors:

Configuring the Record Cache

To use MFC's record caching, you need to do two things:

How big should you make your cache? This depends on your needs and what you are optimizing for. If you expect your users to perform long scrolls or seeks, moving through many records at a time, you probably need a larger cache.

A typical case might be an application that, for example, displays 25 records at a time. For such an application, a cache of 75 records might be a good choice. This would allow quick response for both scrolling up and down and paging up and down.

Filling the Record Cache

DAO fills the cache as you request that records be retrieved from the data source. But you can explicitly fill all or part of the cache at any time by calling CDaoRecordset::FillCache.

When you call FillCache, you can specify either or both of the following:

For more information, see the CDaoRecordset::FillCache member function in the Class Library Reference. For information about the DAO caching mechanism, see the following topics in DAO Help:

See Also   DAO: Where Is..., DAO Recordset