0

我有这个infinispan.xml配置:

<infinispan>
    <cache-container default-cache="dist-sync">
        <transport/>
        <local-cache name="local">
            <expiration lifespan="-1" max-idle="5000"  />
        </local-cache>
        <invalidation-cache name="invalidation" mode="SYNC"/>
        <replicated-cache name="repl-sync" mode="SYNC"/>
        <distributed-cache name="dist-sync" mode="SYNC"/>
    </cache-container>
</infinispan>

如何使用本地缓存名称配置而不是默认缓存(dist-sync)实例化 DefaultCacheManager

4

1 回答 1

2

像这样的东西:

DefaultCacheManager cacheManager = new DefaultCacheManager("infinispan.xml");
Cache<K, V> cache = cacheManager.getCache("local");

文档中的更多信息:https ://infinispan.org/docs/stable/titles/configuring/configuring.html#cache_modes

或javadoc:https://docs.jboss.org/infinispan/11.0/apidocs/org/infinispan/manager/DefaultCacheManager.html#getCache(java.lang.String)

附带说明,DefaultCacheManager.getCache()返回名称在default-cache属性 ( <cache-container default-cache="dist-sync">)中定义的缓存

于 2020-07-06T16:59:14.550 回答