-
1. Re: Question about infinispan-cdi.
sebastian.laskawiec Jan 12, 2017 10:27 AM (in response to seto)When you inject a Cache, the CDI extension tries to find proper configuration (usually a cache configuration and injected Cache objects have the same qualifiers; see this piece of the code). If there is no configuration, a default one is applied.
So if I understood you correctly, you inject multiple Cache objects and you want them to have the same Configuration? If so, you can:
- Update your producer signature to something like this:
- @Produces
public EmbeddedCacheManager defaultClusteredCacheManager(Configuration configuration){
...
return new DefaultCacheManager(..., configuration);
} - Note that Configuration is injected into the producer by CDI
- With this approach each newly created Cache will have the same configuration unless there is a specific Configuration objects matched by Qualifiers.
- @Produces
- Disable CDI extension and write your own logic for injecting caches.
- Update your producer signature to something like this:
-
2. Re: Question about infinispan-cdi.
seto Jan 12, 2017 10:48 AM (in response to sebastian.laskawiec)Not exactly. What I want is a default settings and then with some specific settings to override it.
Here's a small example.
@ConfigureCache("name-cache") @NameCache @Produces public Configuration nameCacheConfig() { return distributeConfig(defaultConfig()).build(); } @ConfigureCache("id-cache") @IdCache @Produces public Configuration idCacheConfig() { return distributeConfig(defaultConfig()).build(); } @ConfigureCache("local-name-cache") @LocalNameCache @Produces public Configuration localNameCacheConfig() { return localConfig(defaultConfig()).build(); } @ConfigureCache("local-id-cache") @LocalIdCache @Produces public Configuration localIdCacheConfig() { return localConfig(defaultConfig()).build(); } private ConfigurationBuilder distributeConfig(ConfigurationBuilder builder) { builder.clustering().cacheMode(CacheMode.DIST_SYNC); return builder; } private ConfigurationBuilder localConfig(ConfigurationBuilder builder) { builder.clustering().cacheMode(CacheMode.LOCAL); return builder; } private ConfigurationBuilder defaultConfig() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.storeAsBinary().enable(); return builder; } @Produces @ApplicationScoped public EmbeddedCacheManager defaultClusteredCacheManager() { System.out.println("new cache manager"); GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder(); ConfigurationBuilder builder = distributeConfig(defaultConfig()); return new DefaultCacheManager(global.build()); } public void killCacheManager(@Disposes EmbeddedCacheManager cacheManager) { System.out.println("kill cache manager"); cacheManager.stop(); }
-
3. Re: Question about infinispan-cdi.
seto Jan 12, 2017 10:42 AM (in response to seto)I want a base config. And a specific config based on the default one.
The code above is what I have done to achieve it.
A multiple @ConfigureCache which I asked for in the issue can resolve the problem of cache sharing the same configuration.
But I want to have a default config. And the ability to inherit the base config.
If I want to share the same config. I can just use the code below. But I can't make any changes based on the default config.
@ConfigureCache("name-cache") @NameCache @Produces public Configuration nameCacheConfig;
-
4. Re: Question about infinispan-cdi.
sebastian.laskawiec Jan 13, 2017 9:28 AM (in response to seto)I'm afraid it can not be further optimized. Your approach seems to be the best fit until we implement ISPN-7351.