Search in sources :

Example 1 with HibernatePropertiesCustomizer

use of org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer in project tutorials by jhkim105.

the class CacheConfig method hibernatePropertiesCustomizer.

@Bean
public HibernatePropertiesCustomizer hibernatePropertiesCustomizer() {
    CachingProvider cachingProvider = new EhcacheCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();
    MutableConfiguration<String, Object> configuration = new MutableConfiguration<>();
    configuration.setStoreByValue(false).setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 1)));
    cacheManager.createCache("user", configuration);
    return hibernateProperties -> hibernateProperties.put(ConfigSettings.CACHE_MANAGER, cacheManager);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) EhcacheCachingProvider(org.ehcache.jsr107.EhcacheCachingProvider) HibernatePropertiesCustomizer(org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CacheManager(javax.cache.CacheManager) Bean(org.springframework.context.annotation.Bean) CachingProvider(javax.cache.spi.CachingProvider) ConfigSettings(org.hibernate.cache.jcache.ConfigSettings) Duration(javax.cache.expiry.Duration) CacheManager(javax.cache.CacheManager) Duration(javax.cache.expiry.Duration) EhcacheCachingProvider(org.ehcache.jsr107.EhcacheCachingProvider) MutableConfiguration(javax.cache.configuration.MutableConfiguration) EhcacheCachingProvider(org.ehcache.jsr107.EhcacheCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) Bean(org.springframework.context.annotation.Bean)

Aggregations

TimeUnit (java.util.concurrent.TimeUnit)1 CacheManager (javax.cache.CacheManager)1 MutableConfiguration (javax.cache.configuration.MutableConfiguration)1 CreatedExpiryPolicy (javax.cache.expiry.CreatedExpiryPolicy)1 Duration (javax.cache.expiry.Duration)1 CachingProvider (javax.cache.spi.CachingProvider)1 EhcacheCachingProvider (org.ehcache.jsr107.EhcacheCachingProvider)1 ConfigSettings (org.hibernate.cache.jcache.ConfigSettings)1 HibernatePropertiesCustomizer (org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer)1 Bean (org.springframework.context.annotation.Bean)1