5.2.2.3. Create a Customized Cache Using a Non-Default Named Cache
A situation can arise where a new customized cache must be created using a named cache that is not the default. The steps to accomplish this are similar to those used when using the default named cache for this purpose.
The difference in approach is due to taking a named cache called
replicatedCache
as the base instead of the default cache.
Procedure 5.3. Create a Customized Cache Using a Non-Default Named Cache
- Read the
replicatedCache
to get the default configuration:EmbeddedCacheManager manager = new DefaultCacheManager("infinispan-config-file.xml"); Configuration rc = cacheManager.getCacheConfiguration("replicatedCache");
- Use the ConfigurationBuilder to construct and modify the desired configuration on a new configuration object:
Configuration c = new ConfigurationBuilder().read(rc).clustering() .cacheMode(CacheMode.DIST_SYNC).l1().lifespan(60000L) .build();
- Register/define your cache configuration with a cache manager:
Cache<String, String> cache = manager.getCache(newCacheName);