此内容没有您所选择的语言版本。

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

Use Data Grid cache templates to add caches with recommended default settings.

Procedure

  1. Create a distributed, synchronous cache from a template and name it "mycache".

    [//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.

  2. 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
      }
    }
    Copy to Clipboard Toggle word wrap

3.2. Creating Caches from XML or JSON Files

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
Copy to Clipboard Toggle word wrap

3.2.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="cacheName" mode="SYNC">
            <memory>
                <object size="20"/>
            </memory>
        </distributed-cache>
    </cache-container>
</infinispan>
Copy to Clipboard Toggle word wrap

3.2.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": {
    "mode": "SYNC",
    "memory": {
      "object": {
        "size": 20
      }
    }
  }
}
Copy to Clipboard Toggle word wrap

3.3. Adding Cache Entries

Add data to caches with the Data Grid CLI.

Prerequisites

  • Create a cache named "mycache" and cd into it.

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

Procedure

  1. Put an entry into "mycache".

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

    If not in the context of a cache, use the --cache= parameter. For example:

    [//containers/default]> put --cache=mycache hello world
    Copy to Clipboard Toggle word wrap
  2. Get the entry to verify it.

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

3.4. Clearing Caches and Deleting Entries

Remove data from caches with the Data Grid CLI.

Procedure

  • Clear caches. This command deletes all entries from a cache.

    [//containers/default]> clearcache mycache
    Copy to Clipboard Toggle word wrap
  • Remove specific entries from a cache.

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

3.5. Deleting Caches

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

Procedure

  • Remove caches with the drop command.

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

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部