diff --git a/pom.xml b/pom.xml index ca1a4c74bdff54d379be07ba557f1e41ec469193..82e78e181b18c9c14a27439864e2f20eec372d08 100644 --- a/pom.xml +++ b/pom.xml @@ -79,6 +79,16 @@ <scope>runtime</scope> </dependency> + <!-- EhCache --> + <dependency> + <groupId>javax.cache</groupId> + <artifactId>cache-api</artifactId> + </dependency> + <dependency> + <groupId>org.ehcache</groupId> + <artifactId>ehcache</artifactId> + </dependency> + <!-- webjars --> <dependency> <groupId>org.webjars</groupId> diff --git a/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java b/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java index 8798bfb50fe9b7fe27a0a054b2995215f6f65c9e..4bc23bbe6dad115ce6af5dec0c9fdd036cc1a6d5 100755 --- a/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java +++ b/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java @@ -1,14 +1,30 @@ 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.context.annotation.Configuration; +import org.springframework.cache.jcache.JCacheCacheManager; 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 @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); + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index fb3e513c36aabfc2307ae08310c4ffb59d74535a..fb07c6c5070c004ca695fa4b0a8885d059927ba8 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -24,6 +24,3 @@ logging.level.org.springframework=INFO # Active Spring profiles spring.profiles.active=production - -# Caching -spring.cache.cache-names=vets