Quarkus Infinispan Embedded
The new Infinispan Embedded Quarkus extension simplifies using Infinispan as an embedded data grid or cache in Quarkus applications.
-
Embedded Infinispan: Run Infinispan in the same process as your application, eliminating the need for a standalone server.
-
Seamless Quarkus Integration: Optimized for Quarkus, providing fast startup, low memory footprint, and simplified configuration.
-
Flexible Caching and Data Grid Capabilities: Easily store and manage data in-memory for high performance and scalability.
This extension is ideal for developers who want to build high-speed, lightweight applications without the overhead of managing external data services.
Quick Overview
To incorporate Quarkus Infinispan Embedded into your Quarkus project, add the following Maven dependency:
<dependency>
<groupId>io.quarkiverse.infinispan</groupId>
<artifactId>quarkus-infinispan-embedded</artifactId>
<version>1.0.0</version>
</dependency>
package io.quarkiverse.infinispan.embedded.samples;
import jakarta.inject.Inject;
import org.infinispan.Cache;
import org.infinispan.commons.api.CacheContainerAdmin;
import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.manager.EmbeddedCacheManager;
import io.quarkus.logging.Log;
import io.quarkus.runtime.QuarkusApplication;
import io.quarkus.runtime.annotations.QuarkusMain;
@QuarkusMain
public class MyServiceExample implements QuarkusApplication {
@Inject
private EmbeddedCacheManager cacheManager; (1)
@Override
public int run(String... args) {
Configuration config = new ConfigurationBuilder()
.clustering().cacheMode(CacheMode.DIST_ASYNC).build();
Log.info(cacheManager.administration() (2)
.withFlags(CacheContainerAdmin.AdminFlag.VOLATILE)
.getOrCreateCache("mycache", config));
Cache<String, String> mycache = cacheManager.getCache("mycache");
mycache.put("greeting", "Hello world!");
Log.info(mycache.get("greeting"));
return 0;
}
}
1 | The @Inject annotation injects the EmbeddedCacheManager. |
2 | Use the EmbeddedCacheManager. Scope if the bean is @Singleton |
Configuration Settings
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Configuration property |
Type |
Default |
---|---|---|
The configured Infinispan embedded xml file which is used by the managed EmbeddedCacheManager and its Caches Environment variable: |
string |
|
Sets a cluster with defaults. Environment variable: |
boolean |
|