Local Cache Map with Embedded Infinispan
What You Will Learn
How to create a local embedded Infinispan cache manager, define a cache, and perform basic put and get operations using the java.util.Map-like API.
Prerequisites
-
Java 17+
Step 1: Add the Embedded Dependency
Add Infinispan core to your pom.xml:
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
</dependency>
Step 2: Create a Cache Manager and Cache
Create a local (non-clustered) cache manager and define a cache with default configuration:
// Construct a simple local cache manager with default configuration
cacheManager = new DefaultCacheManager();
// Define local cache configuration
cacheManager.defineConfiguration("local", new ConfigurationBuilder().build());
// Obtain the local cache
cache = cacheManager.getCache("local");
Step 3: Store and Retrieve Values
Use the familiar put and get methods from the java.util.Map interface:
// Store a value
cache.put("key", "value");
// Retrieve the value and print it out
System.out.printf("key = %s\n", cache.get("key"));
Step 4: Run the Tutorial
mvn package exec:java
The output prints key = value, confirming the cache stores and retrieves entries correctly.
What’s Next
-
Try multimap caching to store multiple values per key
-
Add Java Streams processing on cache data
-
Explore distributed caching across cluster nodes


