5.2.2.2. Create a Customized Cache Using the Default Named Cache
The default cache configuration (or any customized configuration) can serve as a starting point to create a new cache.
As an example, if the
infinispan-config-file.xml specifies the configuration for a replicated cache as a default and a distributed cache with a customized lifespan value is required. The required distributed cache must retain all aspects of the default cache specified in the infinispan-config-file.xml file except the mentioned aspects.
To customize the default cache to fit the above example requirements, use the following steps:
Procedure 5.2. Customize the Default Cache
- Read an instance of a default Configuration object to get the default configuration:
EmbeddedCacheManager manager = new DefaultCacheManager("infinispan-config-file.xml"); Configuration dcc = cacheManager.getDefaultCacheConfiguration();EmbeddedCacheManager manager = new DefaultCacheManager("infinispan-config-file.xml"); Configuration dcc = cacheManager.getDefaultCacheConfiguration();Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Use the ConfigurationBuilder to construct and modify the cache mode and L1 cache lifespan on a new configuration object:
Configuration c = new ConfigurationBuilder().read(dcc).clustering().cacheMode(CacheMode.DIST_SYNC).l1().lifespan(60000L).build();
Configuration c = new ConfigurationBuilder().read(dcc).clustering().cacheMode(CacheMode.DIST_SYNC).l1().lifespan(60000L).build();Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Register/define your cache configuration with a cache manager:
Cache<String, String> cache = manager.getCache(newCacheName);
Cache<String, String> cache = manager.getCache(newCacheName);Copy to Clipboard Copied! Toggle word wrap Toggle overflow