Home | Overview | How Do I | FAQ | Sample | Tutorial | ODBC 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:
Is record caching right for your application? This depends on several factors:
To use MFC's record caching, you need to do two things:
Specify the first of the records to be cached by giving its bookmark in a call to CDaoRecordset::SetCacheStart. You can obtain a record's bookmark by moving to the record and calling CDaoRecordset::GetBookmark. GetBookmark returns a COleVariant value that you can store in a variable. Use the variable in your SetCacheStart call.
Call CDaoRecordset::SetCacheSize to specify how many records are to be cached.
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.
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