Cache sizes¶
Cache sizes can be defined in directory.xml and will be configured only once at the server bootstrap through initialization methods. As of the latest update, the location for configuring cache sizes is under /server/{default|<serverID>}/cache-size instead of the older location /server/{default|<serverID>}/persistence/cache-size. The old location is still supported for backward compatibility, but using it will trigger a log warning like:
The cache size for <className> is initialized from a deprecated location. Please move it from /server/{default|<serverID>}/persistent/cache-size to /server/{default|<serverID>}/cache-size.
If a cache size is configured in both locations, the value from the new location takes precedence. Here's an example of the new format:
<node class="container" name="server">
<node class="container" name="default">
<node class="container" name="cache-size">
</node>
</node>
</node>
There are two types of caches that can be configured:
- LRUCache: The name of the cache will be the class name used when configuring the cache size (if a discriminator is provided, it will also be included in the name). Alongside the name, the cache can be provided with a function which confirms whether an expiration candidate element may actually be expired and a policy to follow when capacity cannot be ensured, due to the function vetoing expiration candidates.
- HashMap: Only the capacity (cache size) is used to create it.
- LinkedHashMap: Similar to
HashMapbut maintains insertion order. Only the capacity (cache size) is used to create it. - IdentityHashMap: Useful for specialized identity-based caching scenarios. Only the capacity (cache size) is used to create it.
- Array: A fixed-size array used as a cache. The array is created using the configured or default size and supports typed values via Java reflection.
cache-size: Main container which stores all the cache size configurations. Cache size are read by iterating over all the containers insidecache-size.- size container: Container that stores a single cache-size configuration. It does not have a specific name set.
class-name: The name of the class used to identify which cache the size belongs to.size: The size that will be used by the cache.discriminator: An identifier used to get the correct cache size when multiple cache sizes are defined for the same class. A discriminator can be used even if there is a single cache that needs to be configured in a class, but it has to be used when initializing to create the cache with the configured value.
To configure a single cache size for a class, use the following structure in the /server/{default|<serverID>}/cache-size container:
<node class="container" name="01"> <!-- container name is unrelated and it doesn't affect the configuration -->
<node class="string" name="class-name">
<node-attribute name="value" value="com.goldencode.p2j.persist.BufferManager"/>
</node>
<node class="integer" name="size">
<node-attribute name="value" value="10000"/>
</node>
</node>
To configure multiple cache sizes for a class, the same structure as above is used, but an additional discriminator node is added.
<node class="container" name="08">
<node class="string" name="class-name">
<node-attribute name="value" value="com.goldencode.p2j.persist.FastFindCache"/>
</node>
<node class="integer" name="size">
<node-attribute name="value" value="16"/>
</node>
<node class="string" name="discriminator">
<node-attribute name="value" value="L2"/>
</node>
</node>
Note that a container needs to be defined for each cache size and the discriminator will be used to make the difference between multiple cache sizes defined for the same class.
The list of caches that can have their size configured:
com.goldencode.p2j.persist.BufferManager:convertedNamesdefault size is10000;com.goldencode.p2j.persist.DynamicTablesHelper:cachedefault size is8192;com.goldencode.p2j.persist.DmoMetadataManager:dynamicTablesdefault size is16384;com.goldencode.p2j.persist.FQLHelperCache:cachedefault size is8192;com.goldencode.p2j.persist.FQLPreprocessor:cachedefault size is2048(without a discriminator) andastCachedefault size is8192(the discriminator is"ast");com.goldencode.p2j.persist.Persistence:staticQueryCachedefault size is1024;com.goldencode.p2j.persist.orm.Persister:updateCachedefault size is4096;com.goldencode.p2j.persist.orm.Session:cachedefault size is1024;com.goldencode.p2j.persist.FastFindCache:l2Cachedefault size is10(the discriminator is"L2") andl3Cachedefault size is100(the discriminator is"L3");com.goldencode.p2j.persist.SortCriterion:cachedefault size is65536;com.goldencode.p2j.persist.DynamicQueryHelper:lvl1Cachedefault size is65536(the discriminator is"lvl1") andlvl2Cachedefault size is16384(the discriminator is"lvl2");com.goldencode.p2j.persist.DynamicValidationHelper:cachedefault size is65536;com.goldencode.p2j.persist.orm.TempTableDataSourceProvider:psCachedefault size is8192;com.goldencode.p2j.util.SourceNameMapper:sourceCachedefault size is8(the discriminator is"source"),searchPathCachedefault size is64(the discriminator is"search"),SourceNameMapperCache.convertedNamesdefault size is16384(the discriminator is"names").com.goldencode.p2j.util.integer:STATIC_CACHE— default size:12000(discriminator:"static-cache")DYNAMIC_CACHE— default size:2048(discriminator:"dynamic-cache")
com.goldencode.p2j.util.int64:STATIC_CACHE— default size:12000(discriminator:"static-cache")DYNAMIC_CACHE— default size:2048(discriminator:"dynamic-cache")
com.goldencode.p2j.util.character:CHARACTER_CONSTANTS— default size:1024(discriminator:"character-cache")
Note that even if the cache belongs to an inner class, the configuration will always use the main class when configuring the cache size.
The following caches will be configured throughCacheManager after #8281 is finished and not be available anymore:
com.goldencode.p2j.persist.DynamicQueryHelper:lvl1Cachedefault size is65536andlvl2Cachedefault size is16384;lvl1Cacheandlvl2Cachecan be configured in the/server/default/standard/runtime/default/container.lvl1Cacheneeds to be configured using thedynamic-query-cache-lvl1-sizenode andlvl2Cachewith thedynamic-query-cache-lvl2-sizenode:<node class="container" name="server"> <node class="container" name="default"> <node class="container" name="standard"> <node class="container" name="runtime"> <node class="container" name="default"> ... <node class="integer" name="dynamic-query-cache-lvl1-size"> <node-attribute name="value" value="65536"/> </node> <node class="integer" name="dynamic-query-cache-lvl2-size"> <node-attribute name="value" value="16384"/> </node> </node> </node> ... </node> </node> </node>com.goldencode.p2j.persist.DynamicValidationHelper:cachedefault size is65536;cachecan be configured in the/server/default/standard/runtime/default/container.cacheneeds to be configured using thedynamic-valexp-cache-sizenode:<node class="container" name="server"> <node class="container" name="default"> <node class="container" name="standard"> <node class="container" name="runtime"> <node class="container" name="default"> ... <node class="integer" name="dynamic-valexp-cache-size"> <node-attribute name="value" value="65536"/> </node> </node> </node> ... </node> </node> </node>
All DynamicQueryHelper and DynamicValidationHelper caches can be configured in the /server/default/runtime/default/ container which is the default when no configuration is found in the /server/default/standard/runtime/default/ container.