第3章 マルチマップキャッシュ
3.1. マルチマップキャッシュ
MultimapCache は、キーを値にマップするキャッシュで、各キーには複数の値を含めることができます。現在、ライブラリーモードでのみ機能します。
3.2. Maven を使用した MultimapCache のインストール
Maven プロジェクトで MultimapCache を利用できるようにするには、pom.xml を以下のように設定します。
pom.xml
<dependency> <groupId>org.infinispan</groupId> <artifactId>infinispan-multimap</artifactId> <version>...</version> <!-- 7.2.0 or later --> </dependency>
3.3. マルチマップキャッシュの作成
以下のようにコードを使用して、MultimapCache を作成します。
// 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. MultimapCache の使用例
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");
});
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.