The situation when multiple JBoss Cache instances are used is very similar to the single cache case:
Here the user should specify
MultiplexedJBossCacheRegionFactory
as their
hibernate.cache.region.factory_class
. The
MultiplexedJBossCacheRegionFactory
shares
almost all its code with SharedJBossCacheRegionFactory
;
the main difference is it constructs a different CacheInstanceManager
implementation -- the MultiplexedCacheInstanceManager
.
MultiplexedCacheInstanceManager
differs from
SharedCacheInstanceManager
in that it does
not directly instantiate a cache. Rather, it creates an
instance of org.jboss.cache.CacheManager
,
providing it with a ChannelFactory
and the
location of the user-specified cache configuration file. The
CacheManager
parses the configuration file.
MultiplexedCacheInstanceManager
analyzes
Hibernate's configuration to determine the name of the desired
cache configuration for entities, collections, queries and
timestamps. See Section 3.1.5, “The MultiplexedJBossCacheRegionFactory
” for
details. It then asks its CacheManager
to
provide each needed cache. In the diagram, two different caches are needed:
One, using the "optimistic-entity" configuration, that is used for entities, collections and queries
Another, with the "timestamps-cache" configuration, that is used for timestamps.
Both the "optimistic-entity" configuration and the "timestamps-cache"
configuration specify the use of the "udp" JGroups channel
configuration, so the CacheManager
's
ChannelFactory
will ensure that they share
the underlying JGroups resources.
The way the region factory creates regions is exactly the same as in the single JBoss Cache case; the only difference is the region factory's internal reference to its timestamps cache now points to a different cache object from the entity, collection and query cache references.