Cache Management

All

CacheManager is vital for cache management, acting as a container for caches and controls their lifecycle, managing global configuration and common data structures.

But not just this, other resources (for example thread pools) and finally, it manages the cluster.

Considering this, there are possibly three scenarios when using CacheManager RHDG (library mode) feature:

I will explain a possible scenario: one CacheManager per JVM.

org.infinispan.manager.DefaultCacheManager;
CacheManager manager = CacheManager.getInstance("my-config-file.xml");
Cache<String, Person> entityCache = manager.getCache("myEntityCache");
entityCache.put("aPerson", new Person());

ConfigurationBuilder confBuilder = new ConfigurationBuilder();
confBuilder.clustering().cacheMode(CacheMode.REPL_SYNC);
manager.createCache("myReplicatedCache", confBuilder.build());
Cache<String, String> replicatedCache = manager.getCache("myReplicatedCache");

In this scenario one creates the cache manager using themy-config-file.xml configuration file, gets the cache and sets up the mode and creates a another cache.

References for cachemanager configuration

CacheManager that spawn the caches, are very heavy some documentation bring that only one should be used per JVM.

The other ones ( Separate CacheManager) I will leave for later, but this can be spotted seen on the logs as:

[timestamp] INFO [org.infinispan.CLUSTER] (jgroups-n,exampleNode) ISPN100000: Node exampleNode joined the cluster
[timestamp] INFO [org.infinispan.CLUSTER] (jgroups-m,example) ISPN100000: Node exampleNode joined the cluster

Interestingly, for JMX it is possible to use it with multiple CacheManager, except one needs to enable it:

new GlobalConfigurationBuilder().globalJmxStatistics().allowDuplicateDomains(true)

But it is also wise to set a different domain, as explained on this StackOverflow question.

new GlobalConfigurationBuilder().globalJmxStatistics().jmxDomain("domain")

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s