Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update infinispan cache configuration #8720

Merged
merged 3 commits into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions generators/server/templates/build.gradle.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ dependencies {
compile "com.hazelcast:hazelcast-spring"
<%_ } _%>
<%_ if (cacheProvider === 'infinispan') { _%>
compile "org.hibernate:hibernate-infinispan"
compile "org.infinispan:infinispan-hibernate-cache"
<%_ } _%>
<%_ if (cacheProvider === 'infinispan') {_%>
compile "org.infinispan:infinispan-spring-boot-starter"
compile "org.infinispan:infinispan-spring-boot-starter-embedded"
compile "org.infinispan:infinispan-core"
compile "org.infinispan:infinispan-jcache"
compile ("org.infinispan:infinispan-cloud") {
Expand Down
8 changes: 3 additions & 5 deletions generators/server/templates/pom.xml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,14 @@
<%_ } _%>
<%_ if (cacheProvider === 'infinispan') { _%>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-infinispan</artifactId>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-hibernate-cache</artifactId>
</dependency>
<%_ } _%>
<%_ if (cacheProvider === 'infinispan') { _%>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-spring-boot-starter</artifactId>
<artifactId>infinispan-spring-boot-starter-embedded</artifactId>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
Expand All @@ -287,12 +287,10 @@
<groupId>org.infinispan</groupId>
<artifactId>infinispan-jcache</artifactId>
</dependency>
<!--
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-cloud</artifactId>
</dependency>
-->
<%_ } _%>
<%_ if (cacheProvider === 'memcached') { _%>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ import javax.annotation.PreDestroy;
import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.configuration.global.GlobalConfigurationBuilder;
import infinispan.autoconfigure.embedded.InfinispanCacheConfigurer;
import infinispan.autoconfigure.embedded.InfinispanGlobalConfigurer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.jhipster.config.JHipsterProperties;
import java.util.concurrent.TimeUnit;
import org.infinispan.eviction.EvictionType;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.spring.starter.embedded.InfinispanCacheConfigurer;
import org.infinispan.spring.starter.embedded.InfinispanEmbeddedCacheManagerAutoConfiguration;
import org.infinispan.spring.starter.embedded.InfinispanGlobalConfigurer;
import org.infinispan.transaction.TransactionMode;
import infinispan.autoconfigure.embedded.InfinispanEmbeddedCacheManagerAutoConfiguration;
import org.infinispan.jcache.embedded.ConfigurationAdapter;
import org.infinispan.jcache.embedded.JCache;
import org.infinispan.jcache.embedded.JCacheManager;
Expand Down Expand Up @@ -371,14 +371,16 @@ public class CacheConfiguration {
* If the service discovery is not enabled, host discovery will be based on
* the default transport settings defined in the 'config-file' packaged within
* the Jar. The 'config-file' can be overridden using the application property
* <i>jhipster.cache.inifnispan.config-file</i>
* <i>jhipster.cache.infinispan.config-file</i>
*
* <p>
* If no service discovery is defined, you have the choice of 'config-file'
* based on the underlying platform for hosts discovery. Infinispan
* supports discovery natively for most of the platforms like Kubernets/OpenShift,
* AWS, Azure and Google.
*
* @param jHipsterProperties the jhipster properties to configure from
* @return the infinispan global configurer
*/
@Bean
public InfinispanGlobalConfigurer globalConfiguration(JHipsterProperties jHipsterProperties) {
Expand Down Expand Up @@ -441,6 +443,8 @@ public class CacheConfiguration {
* </li>
* </ol>
*
* @param jHipsterProperties the jhipster properties to configure from
* @return the infinispan cache configurer
*/
@Bean
public InfinispanCacheConfigurer cacheConfigurer(JHipsterProperties jHipsterProperties) {
Expand All @@ -449,19 +453,21 @@ public class CacheConfiguration {

return manager -> {
// initialize application cache
manager.defineConfiguration("local-app-data", new ConfigurationBuilder().clustering().cacheMode(CacheMode.LOCAL)
manager.defineConfiguration("local-app-data", new ConfigurationBuilder()
.clustering().cacheMode(CacheMode.LOCAL)
.jmxStatistics().enabled(cacheInfo.isStatsEnabled())
.eviction().type(EvictionType.COUNT).size(cacheInfo.getLocal().getMaxEntries()).expiration()
.memory().evictionType(EvictionType.COUNT).size(cacheInfo.getLocal().getMaxEntries()).expiration()
.lifespan(cacheInfo.getLocal().getTimeToLiveSeconds(), TimeUnit.MINUTES).build());
manager.defineConfiguration("dist-app-data", new ConfigurationBuilder()
.clustering().cacheMode(CacheMode.DIST_SYNC).hash().numOwners(cacheInfo.getDistributed().getInstanceCount())
.jmxStatistics().enabled(cacheInfo.isStatsEnabled()).eviction()
.type(EvictionType.COUNT).size(cacheInfo.getDistributed().getMaxEntries()).expiration().lifespan(cacheInfo.getDistributed()
.getTimeToLiveSeconds(), TimeUnit.MINUTES).build());
manager.defineConfiguration("repl-app-data", new ConfigurationBuilder().clustering().cacheMode(CacheMode.REPL_SYNC)
.jmxStatistics().enabled(cacheInfo.isStatsEnabled())
.eviction().type(EvictionType.COUNT).size(cacheInfo.getReplicated()
.getMaxEntries()).expiration().lifespan(cacheInfo.getReplicated().getTimeToLiveSeconds(), TimeUnit.MINUTES).build());
.memory().evictionType(EvictionType.COUNT).size(cacheInfo.getDistributed().getMaxEntries()).expiration()
.lifespan(cacheInfo.getDistributed().getTimeToLiveSeconds(), TimeUnit.MINUTES).build());
manager.defineConfiguration("repl-app-data", new ConfigurationBuilder()
.clustering().cacheMode(CacheMode.REPL_SYNC)
.jmxStatistics().enabled(cacheInfo.isStatsEnabled())
.memory().evictionType(EvictionType.COUNT).size(cacheInfo.getReplicated().getMaxEntries()).expiration()
.lifespan(cacheInfo.getReplicated().getTimeToLiveSeconds(), TimeUnit.MINUTES).build());

// initialize Hibernate L2 cache
manager.defineConfiguration("entity", new ConfigurationBuilder().clustering().cacheMode(CacheMode.INVALIDATION_SYNC)
Expand Down Expand Up @@ -495,6 +501,9 @@ public class CacheConfiguration {
* <p>
* jCache stats are at instance level. If you need stats at clustering level, then it needs to be retrieved from MBX:org.infinispan
*
* @param cacheManager the embedded cache manager
* @param jHipsterProperties the jhipster properties to configure from
* @return the jcache manager
*/
@Bean
public JCacheManager getJCacheManager(EmbeddedCacheManager cacheManager, JHipsterProperties jHipsterProperties){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
-%>
package <%=packageName%>.config;

import org.hibernate.cache.infinispan.InfinispanRegionFactory;
import org.hibernate.service.ServiceRegistry;
import org.infinispan.hibernate.cache.InfinispanRegionFactory;
import org.infinispan.manager.EmbeddedCacheManager;

import java.util.Properties;
Expand All @@ -39,7 +39,7 @@ public class CacheFactoryConfiguration extends InfinispanRegionFactory {
private static final long serialVersionUID = 1L;

/**
* Defines an Hibernate L2 cache: hibernate-infinispan
* Defines an Hibernate L2 cache: infinispan-hibernate-cache
*/
@Override
protected EmbeddedCacheManager createCacheManager(Properties properties, ServiceRegistry serviceRegistry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ spring:
hibernate.cache.inifinispan.statistics: true
hibernate.cache.use_minimal_puts: true
hibernate.cache.infinispan.entity.expiration.lifespan: 3600000
hibernate.cache.infinispan.entity.eviction.max_entries: 1000
hibernate.cache.infinispan.entity.memory.size: 1000
hibernate.cache.infinispan.jgroups_cfg: default-configs/default-jgroups-tcp.xml
<%_ } _%>
<%_ if (cacheProvider === 'hazelcast') { _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ spring:
hibernate.cache.inifinispan.statistics: false
hibernate.cache.use_minimal_puts: true
hibernate.cache.infinispan.entity.expiration.lifespan: 3600000
hibernate.cache.infinispan.entity.eviction.max_entries: 1000
hibernate.cache.infinispan.entity.memory.size: 1000
hibernate.cache.infinispan.jgroups_cfg: default-configs/default-jgroups-tcp.xml
<%_ } _%>
<%_ if (cacheProvider === 'hazelcast') { _%>
Expand Down