cachedDBM

cachedDBM implements a notion of persistent objects. First and foremostly, it has the syntax of std::map, ie it is a template map object, with a key and value type pair. However, by calling the init() method, you can attach a database file, so that values saved in the cachedDBM are stored on disk, to be accessible at a later time.

The iterator range begin() to end() refers to everything stored in the database. An alternative interface that iterates over the database keys is provided by keys.begin() and keys.end() The database is committed when begin() is called, unless the database was opened readonly. In this latter case, there are potentially items stored in the map which will not be iterated over. The alternative iteration methods firstkey(), nextkey() and eof() is an older interface for iterating over keys.begin() to keys.end(). In this instance, the cachedDBM is not committed when firstkey() is called.

Elements stored in the cachedDBM are not actually written to disk until commit() is called (or the cachedDBM object is destroyed).

Entries in the database can be removed via del(). However, if an item with the same key is in the cache, it will need to be removed via erase() as well, otherwise it will be reinserted in the database at commit time.

Only a very simple caching algorithm is employed, but it seems sufficient for many purposes. If the member max_elem is set, then this acts as an upper limit to the number of items stored in memory. If you request a new item to be loaded via the [] operator, and it will cause the number of items to be exceeded, the cachedDBM object is committed. At least the oldest quarter of the cache is cleared, and up to half of the cache. So if max_elem=100, then one is guaranteed that the previous 50 accessed objects will always be in memory, so can be assigned to a reference.

Classdesc serialisation (XDR serialisation) is used store both keys and value data. The database file are therefore machine independent. As a special exception to serialisation rules, char* can be used as key and data types.



Subsections