infinispaninfinispan-9

infinispan, get cachemanager by passing cache configuration name


I have this infinispan.xml configuration:

<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>

How can I instantiate DefaultCacheManager with the cache name configuration local instead of the default cache (dist-sync)


Solution

  • Something like this:

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

    More info in the documentation: https://infinispan.org/docs/stable/titles/configuring/configuring.html#cache_modes

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

    As a side note, DefaultCacheManager.getCache() returns the cache with name defined in the default-cache attribute (<cache-container default-cache="dist-sync">)