3.2. 添加缓存模板
Data Grid 模式包括可用于创建模板的 *-cache-configuration
元素。然后,您可以根据需要创建缓存,多次使用相同的配置。
流程
- 打开 Data Grid 配置以进行编辑。
-
使用适当的
*-cache-configuration
元素或对象将缓存配置添加到 Cache Manager。 - 保存并关闭您的 Data Grid 配置。
缓存模板示例
XML
JSON
YAML
3.2.1. 从模板创建缓存 复制链接链接已复制到粘贴板!
从配置模板创建缓存。
远程缓存的模板可从 Data Grid 控制台中的 Cache templates 菜单获得。
先决条件
- 将至少一个缓存模板添加到缓存管理器。
流程
- 打开 Data Grid 配置以进行编辑。
-
指定缓存使用
配置属性
或字段继承的模板。 - 保存并关闭您的 Data Grid 配置。
从模板继承的缓存配置
XML
<distributed-cache configuration="my-dist-template" />
<distributed-cache configuration="my-dist-template" />
JSON
{ "distributed-cache": { "configuration": "my-dist-template" } }
{
"distributed-cache": {
"configuration": "my-dist-template"
}
}
YAML
distributedCache: configuration: "my-dist-template"
distributedCache:
configuration: "my-dist-template"
3.2.2. 缓存模板继承 复制链接链接已复制到粘贴板!
缓存配置模板可以从其他模板继承,以扩展和覆盖设置。
缓存模板继承是分层的。要使子配置模板从父项继承,您必须在父模板后面包含它。
另外,对于具有多个值的元素,模板继承性是添加的。从另一个模板继承的缓存会合并该模板中的值,这可能会覆盖属性。
模板继承示例
XML
JSON
YAML
3.2.3. 缓存模板通配符 复制链接链接已复制到粘贴板!
您可以将通配符添加到缓存模板名称。如果您创建名称与通配符匹配的缓存,Data Grid 应用配置模板。
如果缓存名称与多个通配符匹配,则数据网格会抛出异常。
模板通配符示例
XML
JSON
YAML
使用前面的示例,如果您创建一个名为 "async-dist-cache-prod" 的缓存,则 Data Grid 会使用 async-dist-cache reasonable
模板的配置。
3.2.4. 从多个 XML 文件缓存模板 复制链接链接已复制到粘贴板!
将缓存配置模板分成多个 XML 文件,以获得细致的灵活性,并通过 XML 包括(XInclude)引用它们。
Data Grid 为 XInclude 规格提供最少的支持。这意味着您无法使用 xpointer
属性、xi:fallback
元素、文本处理或内容协商。
您还必须将 xmlns:xi="http://www.w3.org/2001/XInclude"
命名空间添加到 infinispan.xml
才能使用 XInclude。
Xinclude 缓存模板
Data Grid 还提供了一个 infinispan-config-fragment-15.0.xsd
模式,供您用于配置片段。
配置片段模式
<local-cache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:infinispan:config:15.0 https://infinispan.org/schemas/infinispan-config-fragment-15.0.xsd" xmlns="urn:infinispan:config:15.0" name="mycache"/>
<local-cache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:infinispan:config:15.0 https://infinispan.org/schemas/infinispan-config-fragment-15.0.xsd"
xmlns="urn:infinispan:config:15.0"
name="mycache"/>