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 initialization (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):
synchLoadRowCountLimit - max number of rows in the table for which the synchronous cache load is performed if defined by configuration. If the number of rows is greater, the table's cache will be loaded asynchronous and this number will be taken for the asynchLoadPriority. The default value is 0 (asynch cache load is not performed if configuration parameters for asynch cache load are not defined).
maxExecuteTimeCacheInit - max time for which the query is not printed in application's log file during the cache initialization. If the time is greater, query (SQL statement, execution time and maxExecutionTime) is printed. The default value is value defined for parameter maxExecuteTime (whose default is 0 - nothing is printed).
queryTimeoutCacheInit - max number of seconds for which the query for cache initialization should be executed. If the limit is exceeded, an exception is thrown. The default value is value defined for parameter QueryTimeout (whose default is 0 - no limit).
queryTimeLimitCacheInit - max number of milliseconds for which the query for cache initialization should be executed and the resulset read from ResultSet. If the limit is exceeded, an Exception is thrown. The default value is value defined for parameter QueryTimeLimit (whose default is 0 - no limit).
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.