Chapter 20. Cache Initialization

For every DataStruct cache, it is possible to define initial query statement which contains "where" clause which is used during DataStruct cache initialization. When cache is created, query with this "where" condition is performed on the database, and the results are put in the DataStruct cache.

Before the query is executed, parameter maxDBrows is set to maxCacheSize using method

setMaxRows(int max)

of <table_name>Query.java class.

Using this method, maximum maxCacheSize DOs will be retrieved from the database and their original DataStruct objects (originalData) will be added to DataStruct cache.

If a table is fully cached, simple queries are done in the memory (even the first time this is done in the cache and not in the Database)

If initial query statement is set to "*", all rows of the table from the database (up to maxCacheSize) will be put in the DataStruct cache.

If initial query statement is set to null, no rows from the table in database will be put in the DataStruct cache during the cache initialiyation (cache would be empty).

The parameter ClassList defines the absolute path to "DODSClassList.xml" file that contains the list of data layer classes names whose caches should be initialized. There are two types of cache initialization: synchronous and asynchronous.

Synchronous cache initialization is performed during the application startup.

Beside ClassList parameter, for aynchronous cache initialization, two more parameters must be defined: asynchLoadThreadNum and asynchLoadPriority.

If parameter asynchLoadThreadNum is defined and has positive value, the asynchronous cache load would be performed with the number of threads defined by this parameter. If the parameter is not defined, or has negative or 0 value, the asynchronous cache initialization will not be performed during the application startup.

The parameter asynchLoadPriority (must be number equal or greater than zero) defines the priority (order) for the table's asynchronous cache load. The lower the number, the sooner the cache for the table will be loaded.

As mentioned, if parameter asynchLoadThreadNum is not defined (or negative) asynchronous cache load will not be performed for any of tables. Caches of the tables that have defined asynchLoadPriority, will not even be initialized synchronous because of this parameter. But, class com.lutris.appserver.server.sql.StandardDatabaseManager has method:

public void asynchInitCaches(int threadNum)

that can be call later. It defines the number of threads for asynchronous cache initialization and calls the initialization. This method can have effect only on tables whose caches were not loaded before.

Beside this main parameters for cache initialization, there are more parameters that can be used during the cache initialization (all are explained in the chapter Caching, in the section about Cache configuration):

When synchronous cache load is performed, the application waits for it to be over before it starts its work. The other case is with asynchronous cache load: the application is running while the caches are being asynchronous loaded.