Chapter 10. Using Data Grid in Red Hat JBoss EAP applications


Red Hat JBoss EAP includes Data Grid modules that you can use in Red Hat JBoss EAP applications. You can do this in two ways:

  • Include the Data Grid libraries in a Red Hat JBoss EAP application.

    When you include the Data Grid libraries within an application, the caches are local to the application and cannot be used by other applications. Additionally, the cache configuration is within the application.

  • Use the Data Grid libraries provided by Red Hat JBoss EAP.

    Using the Data Grid libraries provided by Red Hat JBoss EAP has the following benefits:

    • The cache is shared between applications.
    • The cache configuration is part of Red Hat JBoss EAP standalone or domain XML files.
    • Applications do not include Data Grid libraries, they instead reference the required module from the MANIFEST or jboss-structure.xml configuration files.

The following procedures describe using the Data Grid libraries provided by Red Hat JBoss EAP.

To use Data Grid libraries provided by Red Hat JBoss EAP in your applications, add Data Grid dependency in the application’s pom.xml file.

Procedure

  1. Import the Data Grid dependency management to control the versions of runtime Maven dependencies.

    <dependency>
      <groupId>org.infinispan</groupId>
      <artifactId>infinispan-bom</artifactId>
      <version>${version.infinispan.bom}</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
    Copy to Clipboard Toggle word wrap

    You must define the value for ${version.infinispan.bom}`in the `<properties> section of the pom.xml file.

  2. Declare the required Data Grid dependencies as provided.

    pom.xml

    <dependencies>
      <dependency>
        <groupId>org.infinispan</groupId>
        <artifactId>infinispan-core</artifactId>
        <scope>provided</scope>
      </dependency>
    </dependencies>
    Copy to Clipboard Toggle word wrap

Create Data Grid caches in Red Hat JBoss EAP.

Prerequisites

  • Red Hat JBoss EAP is running

Procedure

  1. Connect to the Red Hat JBoss EAP management CLI.

    $ jboss-cli.sh --connect
    Copy to Clipboard Toggle word wrap
  2. Create a cache container.

    /subsystem=infinispan/cache-container=exampleCacheContainer:add(statistics-enabled=true)
    Copy to Clipboard Toggle word wrap

    This creates a cache container called exampleCacheContainer with statistics enabled.

  3. Add a cache to the cache container.

    /subsystem=infinispan/cache-container=exampleCacheContainer/local-cache=exampleCache:add(statistics-enabled=true)
    Copy to Clipboard Toggle word wrap

    This creates a local cache named exampleCache in the exampleCacheContainer cache container with statistics enabled.

You can access Data Grid caches in your applications through resource lookup.

Prerequisites

  • Red Hat JBoss EAP is running.
  • You have created Data Grid cahches in Red Hat JBoss EAP.

Procedure

  1. You can lookup Data Grid caches in your applications like this:

    @Resource(lookup = "java:jboss/infinispan/cache/exampleCacheContainer/exampleCache")
    private Cache<String, String> ispnCache;
    Copy to Clipboard Toggle word wrap

    This defines a Cache called ispnCache.

  2. You can put, get and remove entries from the cache as follows:

    Get value of a key

    String value = ispnCache.get(key);
    Copy to Clipboard Toggle word wrap

    This retrieves the value of the key in the cache. If the key is not found, null is returned.

    Put value in a key

    String oldValue = ispnCache.put(key,value);
    Copy to Clipboard Toggle word wrap

    This defines a new key if it does not already exist and associates the value passed. If the key already exists, the original value is replaced.

    Remove a key

    String value = ispnCache.remove(key);
    Copy to Clipboard Toggle word wrap

    This removes the key from the cache.

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

© 2026 Red Hat