Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
DB Interface Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

9.3 Caching with RWDBReader

In Section 9.2, we saw how to use the caching mechanism of class RWDBInserter. With class RWDBReader, we can use a similar caching mechanism when receiving data from a database server. To enable the caching features of RWDBReader, we pass a cache size of n > 1 to its producer method. The following example shows how to construct a reader with a cache size of 5.

Example 10: Caching with RWDBReader

In //1, we produce an RWDBReader of cache size 5 from an RWDBSelector.

In //2, we use operator() of RWDBReader to fetch data from the database server; in this case, it fetches five rows, since we set the cache size to 5.

In //3, we shift the first row of the RWDBReader's cache into the variable aInt. After processing the value, we return to step //2, where operator() is called a second time. On this second call to operator(), the RWDBReader returns without a network hit to fetch data, as the second row is already fetched from the database server. We then shift the second row in the RWDBReader's cache into the application variable aInt in //3.

This pattern is repeated until the sixth call to operator(). At the time of this call, the RWDBReader has exhausted its internal cache of rows, and must request a new set of rows from the database server. As you can see, by using caching, the RWDBReader must make only one network trip for every five rows read.

RWDBReader producer methods accept a cache size of 0 by default, which results in the selection of an acceptable default cache size by the Access Module you are using. Please check your Access Module User's Guide for more information.



Previous fileTop of DocumentContentsIndex pageNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.