Blogs Infinispan 14 supporting duplicates on multimap

Infinispan 14 supporting duplicates on multimap

Dear Infinispan community,

With the Infinispan 14 development release 04 multimap cache supports duplicates.

By default supportsDuplicates is set to false and can be configured during initialization.

The following is an example on how you can set multimap to support duplicate key-value pairs:

public class MyEmbeddedMultimapCacheExmaple {

public static void main(String[] args) {
      DefaultCacheManager cacheManager = new DefaultCacheManager();

      MultimapCacheManager multimapCacheManager = EmbeddedMultimapCacheManagerFactory.from(cacheManager);

      multimapCacheManager.defineConfiguration("multimap", new ConfigurationBuilder().build());

      // Get the MultimapCache with duplicates support
      MultimapCache<String, String> multimap = multimapCacheManager.get("multimap", true);

      // Store duplicate values in a key
      CompletableFuture.allOf(
            multimap.put("key", "value1"),
            multimap.put("key", "value1"),
            multimap.put("key", "value3"))
            .whenComplete((nil, ex) -> {
               // Retrieve the values
               multimap.get("key").whenComplete((values, ex2) -> {
                  // Print them out
                  System.out.println(values);

                  System.out.println("Multimap size:" + values.size());
                  // Stop the cache manager and release all resources
                  cacheManager.stop();
               });
            });
   }
}
[value1, value1, value3]
Multimap size: 3

Further reading

Check out for available documentation Infinispan MultimapCache Guide.

Get it, Use it, Ask us!

We’re hard at work on new features, improvements and fixes, so watch this space for more announcements!

Please, download and test the latest release.

The source code is hosted on GitHub. If you need to report a bug or request a new feature, look for a similar one on our GitHub issues tracker. If you don’t find any, create a new issue.

If you have questions, are experiencing a bug or want advice on using Infinispan, you can use GitHub discussions. We will do our best to answer you as soon as we can.

The Infinispan community uses Zulip for real-time communications. Join us using either a web-browser or a dedicated application on the Infinispan chat.

Yusuf Karadag

Yusuf is a student developer at JBoss for the Google Summer of Code 2022 and a newbie software engineer. He has been contributing to the @Infinispan project.