3.2. 添加缓存模板
Data Grid 模式包括可用于创建模板的 *-cache-configuration 元素。然后,您可以多次使用相同的配置创建缓存。
流程
- 打开 Data Grid 配置进行编辑。
-
使用适当的
*-cache-configuration元素或对象添加缓存配置到缓存管理器。 - 保存并关闭您的数据网格配置。
缓存模板示例
XML
<infinispan>
<cache-container>
<distributed-cache-configuration name="my-dist-template"
mode="SYNC"
statistics="true">
<encoding media-type="application/x-protostream"/>
<memory max-count="1000000"
when-full="REMOVE"/>
<expiration lifespan="5000"
max-idle="1000"/>
</distributed-cache-configuration>
</cache-container>
</infinispan>
JSON
{
"infinispan" : {
"cache-container" : {
"distributed-cache-configuration" : {
"name" : "my-dist-template",
"mode": "SYNC",
"statistics": "true",
"encoding": {
"media-type": "application/x-protostream"
},
"expiration" : {
"lifespan" : "5000",
"max-idle" : "1000"
},
"memory": {
"max-count": "1000000",
"when-full": "REMOVE"
}
}
}
}
}
YAML
infinispan:
cacheContainer:
distributedCacheConfiguration:
name: "my-dist-template"
mode: "SYNC"
statistics: "true"
encoding:
mediaType: "application/x-protostream"
expiration:
lifespan: "5000"
maxIdle: "1000"
memory:
maxCount: "1000000"
whenFull: "REMOVE"
3.2.1. 从模板创建缓存
从配置模板创建缓存。
提示
Data Grid Console 中的 Cache 模板 菜单提供了远程缓存的模板。
先决条件
- 在缓存管理器中至少添加一个缓存模板。
流程
- 打开 Data Grid 配置进行编辑。
-
指定缓存使用
configuration属性或字段继承的模板。 - 保存并关闭您的数据网格配置。
从模板继承的缓存配置
XML
<distributed-cache configuration="my-dist-template" />
JSON
{
"distributed-cache": {
"configuration": "my-dist-template"
}
}
YAML
distributedCache: configuration: "my-dist-template"