第 3 章 使用远程缓存
使用 Hot Rod (一个自定义 TCP 二进制线协议)从远程 Data Grid 集群存储和检索数据。
3.1. 设置 RemoteCacheManager
将应用程序配置为在 Data Grid 集群上使用远程缓存。
-
提供 Data Grid 服务器侦听客户端连接的地址,以便启动程序可以创建
RemoteCacheManager
bean。 使用 Spring
@Autowired
注解在应用程序中包含您自己的自定义缓存管理器类:private final RemoteCacheManager cacheManager; @Autowired public YourClassName(RemoteCacheManager cacheManager) { this.cacheManager = cacheManager; }
3.1.1. 属性文件
您可以在 hotrod-client.properties
或 application.properties
中指定属性。
属性可以在这两个属性文件中,但启动程序首先应用 hotrod-client.properties
中的配置,这意味着文件优先于 application.properties
。
hotrod-client.properties
此文件中的属性的格式采用 infinispan.client.hotrodö
的格式,例如:
# List Data Grid servers by IP address or hostname at port 11222. infinispan.client.hotrod.server_list=127.0.0.1:6667
application.properties
此文件中的属性的格式采用 infinispan.remote.*
格式,例如:
# List Data Grid servers by IP address or hostname at port 11222. infinispan.remote.server-list=127.0.0.1:6667
其他资源