Este conteúdo não está disponível no idioma selecionado.
2.2. Using the ConfigurationBuilder API to Configure the Cache API
JBoss Data Grid uses a ConfigurationBuilder API to configure caches.
Caches are configured programmatically using the
ConfigurationBuilder helper object.
The following is an example of a synchronously replicated cache configured programmatically using the ConfigurationBuilder API:
Configuration Explanation:
An explanation of each line of the provided configuration is as follows:
Configuration c = new ConfigurationBuilder().clustering().cacheMode(CacheMode.REPL_SYNC).build();
Configuration c = new ConfigurationBuilder().clustering().cacheMode(CacheMode.REPL_SYNC).build();Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the first line of the configuration, a new cache configuration object (namedc) is created using theConfigurationBuilder. Configurationcis assigned the default values for all cache configuration options except the cache mode, which is overridden and set to synchronous replication (REPL_SYNC).String newCacheName = "repl";
String newCacheName = "repl";Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the second line of the configuration, a new variable (of typeString) is created and assigned the valuerepl.manager.defineConfiguration(newCacheName, c);
manager.defineConfiguration(newCacheName, c);Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the third line of the configuration, the cache manager is used to define a named cache configuration for itself. This named cache configuration is calledrepland its configuration is based on the configuration provided for cache configurationcin the first line.Cache<String, String> cache = manager.getCache(newCacheName);
Cache<String, String> cache = manager.getCache(newCacheName);Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the fourth line of the configuration, the cache manager is used to obtain a reference to the unique instance of thereplthat is held by the cache manager. This cache instance is now ready to be used to perform operations to store and retrieve data.