第1章 組み込みキャッシュの使用
インメモリーデータストレージ向けに Data Grid キャッシュをプロジェクトに直接組み込みます。
1.1. EmbeddedCacheManager Bean の追加 リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
組み込みキャッシュを使用するようにアプリケーションを設定します。
手順
-
infinispan-spring-boot3-starter-embedded
をプロジェクトのクラスパスに追加して、組み込みモードを有効にします。 次の例のように、Spring の
@Autowired
アノテーションを使用して、Java 設定クラスにEmbeddedCacheManager
Bean を含めます。Copy to Clipboard Copied! Toggle word wrap Toggle overflow
これで、次の例のように、アプリケーション内でデータグリッドキャッシュを直接使用する準備が整いました。
cacheManager.getCache("testCache").put("testKey", "testValue"); System.out.println("Received value from cache: " + cacheManager.getCache("testCache").get("testKey"));
cacheManager.getCache("testCache").put("testKey", "testValue");
System.out.println("Received value from cache: " + cacheManager.getCache("testCache").get("testKey"));