DODS provides the possibility for every table to have its cache.
The possible cache types are:
1.None
No caching is available.
2.LRU
The size of the cache is limited by the maximal number of objects that can be stored in it. When the cache is full, the objects in it are being replaced by new objects according to LRU (least recently used) algorithm. This algorithm says that the object which had been used the least recently (in the scale of time, the object to which had been accessed the longest time ago, which is on the end of LRU list) is removed from list and new one is put in front of the LRU list. If maximal number of objects is set to 0, it means that caching is not available (None type) at the moment.
3.Complete
This cache extends HashMap and is unbounded. This cache type is defined by the negative number of maximal cache size.
4.Full (special case of complete caching)
This is a complete cache (HashMap), for which is the entire table queried and cached when the application starts (initial condition is "*"). This is appropriate for tables of "static" data which are accessed frequently.
There is a method, isComplete(), in the cache class that checks if the cache (DataStruct cache) is complete or not. If the cache was not complete at the start, it is not checked if it becomes complete or not. But, if the cache was complete, it is than calculated whether the cache is still complete. The method for setting max cache size (in the situation when cache is not null and new cache size is not zero) for DataStruct cache changes cache implementation (form complete to LRU), only if the cache was complete and the new maxCacheSize is positive. In all other cases, the implementation stays as it was.
It is a little bit different with query caches. They don't define the global caching type, so any change form negative to positive max cache size (and vice versa) changes the cache implementation (Complete or LRU).
When any of the caches (DataStruct or any of query caches) is created from scratch, the procedure is the same. Based on max cache size, the proper implementation is used. The same goes for methods for cache refreshing and enabling.
DODS has two levels of caching:
1.Data Caching level
There is only one LRU cache: cache with DataStruct objects. The keys of this cache are cache handles - Strings in the following form:
"<DataStruct_database_name>.<Table_name>.<String_presentation_of_DataStruct_oid>"
and cache values are, as mentioned before, DataStruct objects.
2.Query caching level
Beside DataStruct object cache, there is a possibility of using three query caches (simple, complex and multi-join). Multi-join cache is included since DODS 6.0. All query caches are also LRU caches. The keys of these caches are Strings in the following form:
"<query_database_name>.<String_presentation_of_query>",
and cache values are Query objects. Query objects are objects of the org.enhydra.dods.cache.QueryCacheItem class.
The QueryCacheItem object stores one query and its necessary data:
Database of the query
List of oids of DataStruct objects that are results of the query. This list can contain all query results, or just some of them.
Number of cached query results
Information whether all results are in result list or not
Information whether the query results are modified (if there have been performed inserts, updates or deletes, the results are modified)
Time needed for query execution
Array of conditions declared in WHERE part of the query (array of org.enhydra.dods.cache.Condition objects). This is needed only for simple queries.
Queries that were created with the query's and QueryBuilder's methods that support joins between tables are stored in multi-join cache. Queries that are supported by DataStruct cache are simple queries. Simple query is query that is not multi-join query and for which cache mechanisms can determine whether DataStruct object is query result or not (and query). Other queries (that are not multi-join queries) are complex queries.
The default values for maximal DataStruct cache size, simple, complex and multi-join query cache are 0 (no caching).