第 2 章 使用嵌入式缓存
在项目中直接嵌入 Data Grid 缓存,以进行内存数据存储。
2.1. 添加 EmbeddedCacheManager Bean 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
配置您的应用程序以使用嵌入式缓存。
流程
-
将
infinispan-spring-boot-starter-embedded
添加到项目的 classpath 中,以启用 Embedded 模式。 使用 Spring
@Autowired
注解在 Java 配置类中包含EmbededCacheManager
bean,如下例所示:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
现在,您可以在应用程序中直接使用 Data Grid 缓存,如下例所示:
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"));