15.3. 缓存容器

缓存容器
缓存容器是子系统使用的缓存的资料库。Infinispan 的默认缓存容器是在 XML 配置文件(standalone-ha.xml、standalone-full-ha.xml、domain.xml)里定义的。其中一个会定义为默认缓存,它将用于群集。

例 15.1. standalone-ha.xml 配置文件里的缓存容器定义:

<subsystem xmlns="urn:jboss:domain:infinispan:1.5">
       <cache-container name="singleton" aliases="cluster ha-partition" default-cache="default">
          <transport lock-timeout="60000"/>
          <replicated-cache name="default" mode="SYNC" batching="true">
             <locking isolation="REPEATABLE_READ"/>
          </replicated-cache>
       </cache-container>
       <cache-container name="web" aliases="standard-session-cache" default-cache="repl" module="org.jboss.as.clustering.web.infinispan">
        <transport lock-timeout="60000"/>
        <replicated-cache name="repl" mode="ASYNC" batching="true">
          <file-store/>
        </replicated-cache>
        <replicated-cache name="sso" mode="SYNC" batching="true"/>
          <distributed-cache name="dist" l1-lifespan="0" mode="ASYNC" batching="true">
           <file-store/>
          </distributed-cache>
        </cache-container>
请注意每个缓存容器里定义的默认缓存。在这个例子的 web 缓存容器里,repl 被定义为默认缓存。因此在群集 Web 会话时 repl 将被使用。
您可以用管理控制器或 CLI 命令来配置缓存容器及缓存属性。但我们不建议修改缓存容器或缓存的名称。
配置缓存容器
你可以用管理 CLI 或管理控制台来配置 Infinispan 的缓存容器。

过程 15.1. 在管理控制台里配置 Infinispan 的缓存容器

  1. 从屏幕顶部选择 Configuration 标签页。
  2. 如果服务器运行于域模式,请从左上角的下拉菜单里选择 hafull-ha
  3. 展开 Subsystems 菜单,然后展开 Infinispan 菜单。选择 Cache Containers
  4. Cache Containers 表里选择缓存容器。
  5. 添加、删除或设置默认的缓存容器

    1. 要创建新的缓存容器,点击 Cache Containers 表里的 Add 按钮。
    2. 要删除缓存容器,从 Cache Containers 表里选择缓存容器,点击 Remove,然后点击 OK 确认。
    3. 要设置默认的缓存容器,点击 Set Default,在下拉列表里输入缓存容器的名称,点击 Save 确认。
  6. 要添加或更新缓存容器的属性,请在 Cache Containers 表里选择缓存容器。在屏幕的 Details 区域里的 AttributesTransportAliases 标签页里选择缓存容器,然后点击 Edit。关于 AttributesTransportAliases 标签页里内容的帮助,请点击 Need Help?

过程 15.2. 在管理 CLI 里配置 Infinispan 的缓存容器

  1. 要获取可配置属性的列表,请输入下列 CLI 命令:
    /profile=profile name/subsystem=infinispan/cache-container=container name:read-resource
  2. 您可以使用管理 CLI 来添加、删除和更新缓存容器。在输入和缓存容器相关的任何命令之前,请确保您在 CLI 命令里使用了正确的配置集。
    1. 添加缓存容器

      要添加缓存容器,请以下列命令为基础:
      /profile=profile-name/subsystem=infinispan/cache-container="cache container name":add
    2. 删除缓存容器

      要删除缓存容器,请以下列命令为基础:
      /profile=profile-name/subsystem=infinispan/cache-container="cache container name":remove
    3. 更新缓存容器属性

      使用 write-attribute 操作来编写新的属性的值。您可以使用 tab completion 功能来帮助输入并提示所有可用的值。下面的例子将 statistics-enabled 更新为 true。
      /profile=profile name/subsystem=infinispan/cache-container=cache container name:write-attribute(name=statistics-enabled,value=true)