FillCache Method

See Also      Applies To

Fills all or a part of a local cache for a CdbRecordset object that contains data from a Microsoft Jet-connected ODBC data source (Microsoft Jet-connected ODBC databases only).

Syntax

VOIDFillCache(LONG lRows = -1, CdbBookmark *pbm = NULL);

Parameters

Type Argument Description
LONG lRows Optional. An integer that specifies the number of rows to store in the cache. If you omit this argument, the value is determined by the CacheSize property setting.
CdbBookmark * pbm = NULL Optional. Pointer to a bookmark. The cache is filled starting from the record indicated by this bookmark. If you omit this argument, the cache is filled starting from the record indicated by the CacheStart property.

Remarks

Caching improves the performance of an application that retrieves data from a remote server. A cache is space in local memory that holds the data most recently retrieved from the server; this assumes that the data will probably be requested again while the application is running. When a user requests data, the Microsoft Jet database engine checks the cache for the data first rather than retrieving it from the server, which takes more time. The cache doesn't save data that doesn't come from an ODBC data source.

Rather than waiting for the cache to be filled with records as they are retrieved, you can use the FillCache method to explicitly fill the cache at any time. This is a faster way to fill the cache because FillCache retrieves several records at once instead of one at a time. For example, while you view each screenful of records, your application uses FillCache to retrieve the next screenful of records for viewing.

Any Microsoft Jet-connected ODBC data source that you access with CdbRecordset objects can have a local cache. To create the cache, open a CdbRecordset object from the remote data source, and then set the CacheSize and CacheStart properties of the CdbRecordset.

If lRows and pbm create a range of records that is partially or entirely outside the range of records specified by the CacheSize and CacheStart properties, the portion outside this range is ignored and will not be loaded into the cache.

If FillCache requests more records than the number remaining in the remote data source, Microsoft Jet retrieves only the remaining records, and no error occurs.

Notes

Usage

#include <afxole.h>
#include <dbdao.h>

CdbDBE   ngine      dben(..., dbUseODBC);
CdbDatabase      dbs;
CdbRecordset      rst;
CdbBookmark      book;

dbs = dben.OpenDatabase(_T("ODBC;..."));
rst = dbs.OpenRecordset(..., dbOpenDynaset);
if (rst.Bookmarkable())
{
   // Remember the current record position.
book = rst.GetBookmark();
   // Start the cache from the current position.
rst.SetCacheStart(book);
   // The cache will hold 25 records.
rst.SetCacheSize(25);
rst.FillCache();
   // Do some work...
rst.MoveNext();
   // Get a few more records.
book = rst.GetBookmark();
rst.FillCache(5, &book);
...
}