Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion data/synapse-data-postgres/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<artifactId>hibernate-jcache</artifactId>
</dependency>
<!-- persistence -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
package io.americanexpress.synapse.data.postgres.config;

import com.zaxxer.hikari.HikariDataSource;
import org.ehcache.config.CacheConfiguration;
import org.ehcache.config.builders.CacheConfigurationBuilder;
import org.ehcache.config.builders.ExpiryPolicyBuilder;
import org.ehcache.config.builders.ResourcePoolsBuilder;
import org.ehcache.jsr107.Eh107Configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
Expand All @@ -24,7 +29,11 @@
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.cache.CacheManager;
import javax.cache.Caching;
import javax.cache.spi.CachingProvider;
import javax.sql.DataSource;
import java.time.Duration;
import java.util.Properties;

/**
Expand Down Expand Up @@ -79,8 +88,9 @@ private Properties additionalHibernateSpringProperties() {
properties.setProperty("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
properties.setProperty("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
properties.setProperty("spring.datasource.initialization-mode", environment.getRequiredProperty("spring.datasource.initialization-mode"));
properties.setProperty("hibernate.cache.use_second_level_cache", "true");
properties.setProperty("hibernate.cache.use_query_cache", "true");
properties.setProperty("hibernate.cache.provider_class", "org.ehcache.hibernate.EhCacheProvider");
properties.setProperty("hibernate.cache.provider_class", "org.ehcache.jsr107.EhcacheCachingProvider");
return properties;
}

Expand All @@ -98,6 +108,25 @@ public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
return entityManagerFactoryBean;
}

@Bean
public CacheManager cacheManager() {
CachingProvider cachingProvider = Caching.getCachingProvider();
CacheManager cacheManager = cachingProvider.getCacheManager();

CacheConfiguration<Object, Object> cacheConfiguration =
CacheConfigurationBuilder.newCacheConfigurationBuilder(
Object.class, Object.class, ResourcePoolsBuilder.heap(1000))
.withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofMinutes(10)))
.build();

javax.cache.configuration.Configuration<Object, Object> configuration =
Eh107Configuration.fromEhcacheCacheConfiguration(cacheConfiguration);

cacheManager.createCache("defaultCache", configuration);

return cacheManager;
}

Comment thread
aazizali marked this conversation as resolved.
Outdated
/**
* Set the packages to Scan property to the entityManagerFactory.
*
Expand Down
7 changes: 3 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -638,15 +638,14 @@
<!--EhCache-->
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<artifactId>ehcache</artifactId>
Comment thread
aazizali marked this conversation as resolved.
Outdated
<version>3.10.8</version>
</dependency>

<!--Hibernate-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.6.15.Final</version>
<artifactId>hibernate-jcache</artifactId>
<version>6.6.15.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
Expand Down