Chapter 3. Performing Cache Operations with the Data Grid CLI
The command line interface (CLI) lets you remotely connect to Data Grid servers to access data and perform administrative functions.
Prerequisites
- Start the Data Grid CLI.
- Connect to a running Data Grid cluster.
3.1. Creating Caches from Templates Copy linkLink copied to clipboard!
Use Data Grid cache templates to add caches with recommended default settings.
Procedure
Create a distributed, synchronous cache from a template and name it "mycache".
[//containers/default]> create cache --template=org.infinispan.DIST_SYNC mycacheTipPress the tab key after the
--template=argument to list available cache templates.Retrieve the cache configuration.
[//containers/default]> describe caches/mycache { "distributed-cache" : { "mode" : "SYNC", "remote-timeout" : 17500, "state-transfer" : { "timeout" : 60000 }, "transaction" : { "mode" : "NONE" }, "locking" : { "concurrency-level" : 1000, "acquire-timeout" : 15000, "striping" : false }, "statistics" : true } }
3.2. Creating Caches from XML or JSON Files Copy linkLink copied to clipboard!
Add caches with custom Data Grid configuration in XML or JSON format.
Procedure
-
Add the path to your configuration file with the
--file=option as follows:
[//containers/default]> create cache --file=prod_dist_cache.xml dist_cache_01
3.2.1. XML Configuration Copy linkLink copied to clipboard!
Data Grid configuration in XML format must conform to the schema and include:
-
<infinispan>root element. -
<cache-container>definition.
Example XML Configuration
<infinispan>
<cache-container>
<distributed-cache name="cacheName" mode="SYNC">
<memory>
<object size="20"/>
</memory>
</distributed-cache>
</cache-container>
</infinispan>
3.2.2. JSON Configuration Copy linkLink copied to clipboard!
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
{
"distributed-cache": {
"mode": "SYNC",
"memory": {
"object": {
"size": 20
}
}
}
}
3.3. Adding Cache Entries Copy linkLink copied to clipboard!
Add data to caches with the Data Grid CLI.
Prerequisites
Create a cache named "mycache" and
cdinto it.[//containers/default]> cd caches/mycache
Procedure
Put an entry into "mycache".
[//containers/default/caches/mycache]> put hello worldTipIf not in the context of a cache, use the
--cache=parameter. For example:[//containers/default]> put --cache=mycache hello worldGet the entry to verify it.
[//containers/default/caches/mycache]> get hello world
3.4. Clearing Caches and Deleting Entries Copy linkLink copied to clipboard!
Remove data from caches with the Data Grid CLI.
Procedure
Clear caches. This command deletes all entries from a cache.
[//containers/default]> clearcache mycacheRemove specific entries from a cache.
[//containers/default]> remove --cache=mycache hello
3.5. Deleting Caches Copy linkLink copied to clipboard!
Drop caches to remove them and delete all data they contain.
Procedure
Remove caches with the drop command.
[//containers/default]> drop cache mycache