A different kind of template: wildcards

Infinispan’s configuration templates are an extremely flexible way to create multiple caches using the same configuration. Configuration inheritance works by explicitly declaring the configuration a specific cache should use.

This works fine when you know the caches you are going to use upfront, but in more dynamic scenarios, this might not be possible. Additionally, if you are using the JCache API, there is no way for you to specify the configuration template you want to use.

Infinispan 9.2 introduces an alternative way to apply templates to caches: wildcards. By creating a template with a wildcard in its name, e.g. basecache*, any cache whose name matches the template name will inherit that configuration.

Let’s show an example:

Above, caches basecache-1 and basecache-2 will use the basecache* configuration. This behaviour also applies when retrieving caches programmatically:

When using the JCache API, using the XML file above and the following code will achieve the same result:

If a cache name matches multiple wildcards, i.e. it is ambiguous, an exception will be thrown.

I will be introducing other new features that Infinispan 9.2 brings to cache configuration in an upcoming blog post. Stay tuned !

Posted by Tristan Tarrant on 2018-02-02
Tags: jcache configuration
back to top