1

Our Thorntail (2.4.0.Final) webapp is using Infinispan as a JCache (JSR-107) provider. We would like to modify Infinispan specific attributes (such as default acquire timeout) in addition to JCache's attributes (such as store-by-value option).

Our current solution isn't working. Here's what we've tried so far.

  • Defined infinispan.xml:
<infinispan
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:infinispan:config:5.2 http://www.infinispan.org/schemas/infinispan-config-9.4.xsd"
        xmlns="urn:infinispan:config:9.4">

    <cache-container>
        <local-cache  name="foo">
            <locking acquire-timeout="15000"/>
        </local-cache>
    </cache-container>
</infinispan>
  • The config above is then used by the following class:
public class CacheManagerProducer {

    @Produces
    @ApplicationScoped
    public CacheManager defaultEmbeddedCacheManager() {
        return Caching.getCachingProvider().getCacheManager(URI.create("infinispan.xml"), this.getClass().getClassLoader());
    }
}
  • FooCache interface is defined as:
@Qualifier
@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)

@Documented
public @interface FooCache {
}
  • Here's how we're configuring cache using JCache API:
@Produces
@FooCache
public Cache<Long, DiscountOrAddition> createDiscoCache(InjectionPoint injectionPoint) {
    MutableConfiguration<Long, DiscountOrAddition> config = new MutableConfiguration<>();
    config.setStoreByValue(true);
    config.setStatisticsEnabled(false);
    config.setManagementEnabled(false);
    return mgr.createCache("foo", config);
}

This is where we fail as foo cache already exists (created as per XML config). Is there a way we could configure existing cache? Or any other alternative way allowing us to stay cache-provider agnostic? Thank you for your answers.

geca
  • 2,711
  • 2
  • 17
  • 26
  • Seems like two conflicting configurations. Try just `mgr.getCache("foo")` – cruftex Jul 30 '19 at 15:37
  • Correct, the JCache config is clashing with the Infinispan's (configured via XML). The solution you proposed doesn't solve the problem i.e we would like to add additional config (such as store by value) via JCache API. – geca Jul 30 '19 at 19:37
  • store by value is the default, you don't need to have this in the config – cruftex Jul 31 '19 at 07:15
  • For a discussion on store by value, see this answer: https://stackoverflow.com/questions/42772288/javax-cache-store-by-reference-vs-store-by-value – cruftex Jul 31 '19 at 07:17
  • Usually the implementation specific configuration is a superset of the JCache configuration, so there is no real need to use the JCache based configuration. In [cache2k](https://cache2k.org) I thought that it is a good idea to merge both configurations, but that gets quite messy and hard to understand. – cruftex Jul 31 '19 at 07:23
  • My recommendation with JCache is to stick with the provider-specific configuration, since the JCache configuration API is very limited. – Galder Zamarreño Sep 02 '19 at 14:55

1 Answers1

2

We encountered similar issue, except defining cache configuration instead cache in the infinispan.xml:

<?xml version="1.0" encoding="UTF-8"?>
<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:infinispan:config:8.2 https://infinispan.org/schemas/infinispan-config-8.2.xsd"
    xmlns="urn:infinispan:config:8.2">

    <cache-container>
        <local-cache-configuration name="foo">
            <locking acquire-timeout="15000"/>
        </local-cache-configuration>
    </cache-container>
</infinispan>

Expecting the above configuration will be used as a template and merged with JCache configuration to create the cache foo. This is working correctly in Infinispan 8.2 stream, but upgrade to 9.4 stream it is not working now. We think this is unintended and already submit a bug report (ISPN-11918)

Sammy Chu
  • 21
  • 1
  • 2