11.2. 创建远程缓存
先决条件
-
确保
cache-api位于您的 classpath 上。 在
pom.xml中添加以下依赖项:<dependency> <groupId>org.infinispan</groupId> <artifactId>infinispan-jcache-remote</artifactId> </dependency>
流程
- 在远程 Data Grid 服务器上创建缓存,并使用默认的 JCache API 配置,如下所示:
import javax.cache.*;
import javax.cache.configuration.*;
// Retrieve the system wide cache manager via org.infinispan.jcache.remote.JCachingProvider
CacheManager cacheManager = Caching.getCachingProvider("org.infinispan.jcache.remote.JCachingProvider").getCacheManager();
// Define a named cache with default JCache configuration
Cache<String, String> cache = cacheManager.createCache("remoteNamedCache",
new MutableConfiguration<String, String>());
11.2.1. 配置远程缓存 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
热 Rod 配置文件包括 infinispan.client.hotrod.cache the 属性,可用于自定义远程缓存。
-
将
hotrod-client.properties文件的 URI 传递给 cacheProvider.getCacheManager (URI)调用,如下所示:
import javax.cache.*;
import javax.cache.configuration.*;
// Load configuration from an absolute filesystem path
URI uri = URI.create("file:///path/to/hotrod-client.properties");
// Load configuration from a classpath resource
// URI uri = this.getClass().getClassLoader().getResource("hotrod-client.properties").toURI();
// Retrieve the system wide cache manager via org.infinispan.jcache.remote.JCachingProvider
CacheManager cacheManager = Caching.getCachingProvider("org.infinispan.jcache.remote.JCachingProvider")
.getCacheManager(uri, this.getClass().getClassLoader(), null);