Chapter 2. 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.

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

  1. Create a CLI connection to Data Grid.
  2. Add cache definitions with the create cache command.

    • Add a cache definition from an XML or JSON file with the --file option.

      [//containers/default]> create cache --file=configuration.xml mycache
      Copy to Clipboard Toggle word wrap
    • Add a cache definition from a template with the --template option.

      [//containers/default]> create cache --template=org.infinispan.DIST_SYNC mycache
      Copy to Clipboard Toggle word wrap
      Tip

      Press the tab key after the --template= argument to list available cache templates.

  3. Verify the cache exists with the ls command.

    [//containers/default]> ls caches
    mycache
    Copy to Clipboard Toggle word wrap
  4. Retrieve the cache configuration with the describe command.

    [//containers/default]> describe caches/mycache
    Copy to Clipboard Toggle word wrap

2.1.1. XML Configuration

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="myCache" mode="SYNC">
          <encoding media-type="application/x-protostream"/>
          <memory max-count="1000000" when-full="REMOVE"/>
        </distributed-cache>
    </cache-container>
</infinispan>
Copy to Clipboard Toggle word wrap

2.1.2. JSON Configuration

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": {
    "name": "myCache",
    "mode": "SYNC",
    "encoding": {
      "media-type": "application/x-protostream"
      },
    "memory": {
      "max-count": 1000000,
      "when-full": "REMOVE"
    }
  }
}
Copy to Clipboard Toggle word wrap

2.2. Adding Cache Entries

Create key:value pair entries in the data container.

Prerequisites

Create a Data Grid cache that can store your data.

Procedure

  1. Create a CLI connection to Data Grid.
  2. Add entries into your cache as follows:

    • Use the put command from the context of a cache:

      [//containers/default/caches/mycache]> put hello world
      Copy to Clipboard Toggle word wrap
    • Use the --cache= with the put command:

      [//containers/default]> put --cache=mycache hello world
      Copy to Clipboard Toggle word wrap
  3. Use the get command to verify entries.

    [//containers/default/caches/mycache]> get hello
    world
    Copy to Clipboard Toggle word wrap

2.3. Clearing Caches and Deleting Entries

Remove data from caches with the Data Grid CLI.

Procedure

  1. Create a CLI connection to Data Grid.
  2. Do one of the following:

    • Delete all entries with the clearcache command.

      [//containers/default]> clearcache mycache
      Copy to Clipboard Toggle word wrap
    • Remove specific entries with the remove command.

      [//containers/default]> remove --cache=mycache hello
      Copy to Clipboard Toggle word wrap

2.4. Deleting Caches

Drop caches to remove them and delete all data they contain.

Procedure

  1. Create a CLI connection to Data Grid.
  2. Remove caches with the drop command.

    [//containers/default]> drop cache mycache
    Copy to Clipboard Toggle word wrap
Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2025 Red Hat