Put Ehcache back

This commit is contained in:
Henri Tremblay 2017-02-16 15:08:30 -05:00
parent 63dadcc07f
commit 443d35eae2
3 changed files with 30 additions and 7 deletions

10
pom.xml
View file

@ -79,6 +79,16 @@
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<!-- EhCache -->
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<!-- webjars --> <!-- webjars -->
<dependency> <dependency>
<groupId>org.webjars</groupId> <groupId>org.webjars</groupId>

View file

@ -1,14 +1,30 @@
package org.springframework.samples.petclinic.system; package org.springframework.samples.petclinic.system;
import javax.cache.configuration.Configuration;
import javax.cache.configuration.MutableConfiguration;
import org.springframework.boot.autoconfigure.cache.CacheManagerCustomizer;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Configuration; import org.springframework.cache.jcache.JCacheCacheManager;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
/** /**
* Cache could be disable in unit test. * Cache could be disabled in unit test.
*/ */
@Configuration @org.springframework.context.annotation.Configuration
@EnableCaching @EnableCaching
@Profile("production") @Profile("production")
class CacheConfig { class CacheConfig implements CacheManagerCustomizer<JCacheCacheManager> {
@Override
public void customize(JCacheCacheManager cacheManager) {
Configuration<Object, Object> cacheConfiguration = createCacheConfiguration();
cacheManager.getCacheManager().createCache("vets", cacheConfiguration);
}
private Configuration<Object, Object> createCacheConfiguration() {
// Create a cache using infinite heap. A real application will want to use an implementation dependent
// configuration that will better fit your needs
return new MutableConfiguration<>().setStatisticsEnabled(true);
}
} }

View file

@ -24,6 +24,3 @@ logging.level.org.springframework=INFO
# Active Spring profiles # Active Spring profiles
spring.profiles.active=production spring.profiles.active=production
# Caching
spring.cache.cache-names=vets