Este conteúdo não está disponível no idioma selecionado.
Chapter 6. Remotely Creating Data Grid Caches
Add caches to Data Grid Server so you can store data.
6.1. Cache Configuration with Data Grid Server Copiar o linkLink copiado para a área de transferência!
Caches configure the data container on Data Grid Server.
You create caches at run-time by adding definitions based on org.infinispan templates or Data Grid configuration through the console, the Command Line Interface (CLI), the Hot Rod endpoint, or the REST endpoint.
When you create caches at run-time, Data Grid Server replicates your cache definitions across the cluster.
Configuration that you declare directly in infinispan.xml is not automatically synchronized across Data Grid clusters. In this case you should use configuration management tooling, such as Ansible or Chef, to ensure that configuration is propagated to all nodes in your cluster.
6.2. Default Cache Manager Copiar o linkLink copiado para a área de transferência!
Data Grid Server provides a default Cache Manager configuration. When you start Data Grid Server, it instantiates the Cache Manager so you can remotely create caches at run-time.
Default Cache Manager
- 1
- Creates a Cache Manager named "default".
- 2
- Exports Cache Manager statistics through the
metricsendpoint. - 3
- Adds a JGroups cluster transport that allows Data Grid servers to automatically discover each other and form clusters.
- 4
- Uses the default TCP stack for cluster traffic.
- 5
- Individual name for the node, must be unique across the cluster. Uses a unified hostname by default.
Examining the Cache Manager
After you start Data Grid Server and add user credentials, you can access the default Cache Manager through the Command Line Interface (CLI) or REST endpoint as follows:
CLI: Use the
describecommand in the default container.[//containers/default]> describe
[//containers/default]> describeCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
REST: Navigate to
<server_hostname>:11222/rest/v2/cache-managers/default/in any browser.
6.3. Creating Caches with the Data Grid Console Copiar o linkLink copiado para a área de transferência!
Dynamically add caches from templates or configuration files through the Data Grid console.
Prerequisites
Create a user and start at least one Data Grid server instance.
Procedure
-
Navigate to
<server_hostname>:11222/console/in any browser. - Log in to the console.
- Open the Data Container view.
- Select Create Cache and then add a cache from a template or with Data Grid configuration in XML or JSON format.
- Return to the Data Container view and verify your Data Grid cache.
6.4. Creating Caches with the Data Grid Command Line Interface (CLI) Copiar o linkLink copiado para a área de transferência!
Use the Data Grid CLI to add caches from templates or configuration files in XML or JSON format.
Prerequisites
Create a user and start at least one Data Grid server instance.
Procedure
- Create a CLI connection to Data Grid.
Add cache definitions with the
create cachecommand.Add a cache definition from an XML or JSON file with the
--fileoption.[//containers/default]> create cache --file=configuration.xml mycache
[//containers/default]> create cache --file=configuration.xml mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add a cache definition from a template with the
--templateoption.[//containers/default]> create cache --template=org.infinispan.DIST_SYNC mycache
[//containers/default]> create cache --template=org.infinispan.DIST_SYNC mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow TipPress the tab key after the
--template=argument to list available cache templates.
Verify the cache exists with the
lscommand.[//containers/default]> ls caches mycache
[//containers/default]> ls caches mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow Retrieve the cache configuration with the
describecommand.[//containers/default]> describe caches/mycache
[//containers/default]> describe caches/mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow
6.5. Creating Caches with Hot Rod Clients Copiar o linkLink copiado para a área de transferência!
Programmatically create caches on Data Grid Server through the RemoteCacheManager API.
The following procedure demonstrates programmatic cache creation with the Hot Rod Java client. However Hot Rod clients are available in different languages such as Javascript or C++.
Prerequisites
- Create a user and start at least one Data Grid server instance.
- Get the Hot Rod Java client.
Procedure
Configure your client with the
ConfigurationBuilderclass.Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Use the
XMLStringConfigurationclass to add cache definitions in XML format. Call the
getOrCreateCache()method to add the cache if it already exists or create it if not.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create caches with
org.infinispantemplates as in the following example with thecreateCache()invocation:private void createCacheWithTemplate() { manager.administration().createCache("myCache", "org.infinispan.DIST_SYNC"); System.out.println("Cache created."); }private void createCacheWithTemplate() { manager.administration().createCache("myCache", "org.infinispan.DIST_SYNC"); System.out.println("Cache created."); }Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Next Steps
Try some working code examples that show you how to create remote caches with the Hot Rod Java client. Visit the Data Grid Tutorials.
6.6. Creating Data Grid Caches with HTTP Clients Copiar o linkLink copiado para a área de transferência!
Add cache definitions to Data Grid servers through the REST endpoint with any suitable HTTP client.
Prerequisites
Create a user and start at least one Data Grid server instance.
Procedure
-
Create caches with
POSTrequests to/rest/v2/caches/$cacheName.
Use XML or JSON configuration by including it in the request payload.
POST /rest/v2/caches/mycache
POST /rest/v2/caches/mycache
Use the ?template= parameter to create caches from org.infinispan templates.
POST /rest/v2/caches/mycache?template=org.infinispan.DIST_SYNC
POST /rest/v2/caches/mycache?template=org.infinispan.DIST_SYNC
6.7. Data Grid Configuration Copiar o linkLink copiado para a área de transferência!
Data Grid configuration in XML and JSON format.
6.7.1. XML Configuration Copiar o linkLink copiado para a área de transferência!
Data Grid configuration in XML format must conform to the schema and include:
-
<infinispan>root element. -
<cache-container>definition.
Example XML Configuration
6.7.2. JSON Configuration Copiar o linkLink copiado para a área de transferência!
Data Grid configuration in JSON format:
- Requires the cache definition only.
Must follow the structure of an XML configuration.
- XML elements become JSON objects.
- XML attributes become JSON fields.
Example JSON Configuration