2.2. Creating CacheManagers
2.2.1. Create a New RemoteCacheManager Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Example 2.1. Configure a New RemoteCacheManager
Configuration Explanation
An explanation of each line of the provided configuration is as follows:
- Use the
ConfigurationBuilder()
method to configure a new builder. The.addServer()
property adds a remote server, specified via the.host(<hostname|ip>)
and.port(<port>)
properties.Configuration conf = new ConfigurationBuilder().addServer().host(<hostname|ip>).port(<port>).build();
Configuration conf = new ConfigurationBuilder().addServer().host(<hostname|ip>).port(<port>).build();
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Create a new
RemoteCacheManager
using the supplied configuration.RemoteCacheManager manager = new RemoteCacheManager(conf);
RemoteCacheManager manager = new RemoteCacheManager(conf);
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Retrieve the default cache from the remote server.
RemoteCache defaultCache = manager.getCache();
RemoteCache defaultCache = manager.getCache();
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.2.2. Create a New Embedded Cache Manager Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Use the following instructions to create a new EmbeddedCacheManager without using CDI:
Procedure 2.1. Create a New Embedded Cache Manager
- Create a configuration XML file. For example, create the
my-config.file.xml
file on the classpath (in theresources/
folder) and add the configuration information in this file. - Use the following programmatic configuration to create a cache manager using the configuration file:
EmbeddedCacheManager manager = new DefaultCacheManager("my-config-file.xml"); Cache defaultCache = manager.getCache();
EmbeddedCacheManager manager = new DefaultCacheManager("my-config-file.xml"); Cache defaultCache = manager.getCache();
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
The outlined procedure creates a new EmbeddedCacheManager using the basic configuration specified.
2.2.3. Create a New Embedded Cache Manager Using CDI Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Use the following steps to create a new EmbeddedCacheManager instance using CDI:
Procedure 2.2. Use CDI to Create a New EmbeddedCacheManager
- Specify a default configuration:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Inject the default cache manager.
... @Inject EmbeddedCacheManager cacheManager; ...
... @Inject EmbeddedCacheManager cacheManager; ...
Copy to Clipboard Copied! Toggle word wrap Toggle overflow