Search

Chapter 3. The Multimap Cache

download PDF

3.1. The Multimap Cache

The MultimapCache is a cache that maps keys to values in which each key can contain multiple values. It currently only functions in Library Mode.

3.2. Installing MultimapCache using Maven

To make the MultimapCache available in the Maven project configure the pom.xml as follows:

pom.xml

<dependency>
   <groupId>org.infinispan</groupId>
   <artifactId>infinispan-multimap</artifactId>
   <version>...</version> <!-- 7.2.0 or later -->
</dependency>

3.3. Creating a Multimap Cache

Create a MultimapCache using code like the following:

// create or obtain your EmbeddedCacheManager
EmbeddedCacheManager cm = ... ;

// create or obtain a MultimapCacheManager passing the EmbeddedCacheManager
MultimapCacheManager multimapCacheManager = EmbeddedMultimapCacheManagerFactory.from(cm);

// define the configuration for the multimap cache
multimapCacheManager.defineConfiguration(multimapCacheName, c.build());

// get the multimap cache
multimapCache = multimapCacheManager.get(multimapCacheName);

3.4. Example MultimapCache Usage

Below is code demonstrating how to use MultimapCache:

MultimapCache<String, String> multimapCache = ...;

multimapCache.put("girlNames", "marie")
             .thenCompose(r1 -> multimapCache.put("girlNames", "oihana"))
             .thenCompose(r3 -> multimapCache.get("girlNames"))
             .thenAccept(names -> {
                          if(names.contains("marie"))
                              System.out.println("Marie is a girl name");

                           if(names.contains("oihana"))
                              System.out.println("Oihana is a girl name");
                        });
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.

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.

© 2024 Red Hat, Inc.