Skip to content
Snippets Groups Projects
Commit 75912a06 authored by Stephane Nicoll's avatar Stephane Nicoll
Browse files

Polish contribution

Closes gh-229
parent 443d35ea
No related branches found
No related tags found
No related merge requests found
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<!-- EhCache --> <!-- caching -->
<dependency> <dependency>
<groupId>javax.cache</groupId> <groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId> <artifactId>cache-api</artifactId>
......
...@@ -3,9 +3,9 @@ package org.springframework.samples.petclinic.system; ...@@ -3,9 +3,9 @@ package org.springframework.samples.petclinic.system;
import javax.cache.configuration.Configuration; import javax.cache.configuration.Configuration;
import javax.cache.configuration.MutableConfiguration; import javax.cache.configuration.MutableConfiguration;
import org.springframework.boot.autoconfigure.cache.CacheManagerCustomizer; import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.jcache.JCacheCacheManager; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
/** /**
...@@ -14,17 +14,19 @@ import org.springframework.context.annotation.Profile; ...@@ -14,17 +14,19 @@ import org.springframework.context.annotation.Profile;
@org.springframework.context.annotation.Configuration @org.springframework.context.annotation.Configuration
@EnableCaching @EnableCaching
@Profile("production") @Profile("production")
class CacheConfig implements CacheManagerCustomizer<JCacheCacheManager> { class CacheConfig {
@Override @Bean
public void customize(JCacheCacheManager cacheManager) { public JCacheManagerCustomizer cacheManagerCustomizer() {
Configuration<Object, Object> cacheConfiguration = createCacheConfiguration(); return cm -> {
cacheManager.getCacheManager().createCache("vets", cacheConfiguration); Configuration<Object, Object> cacheConfiguration = createCacheConfiguration();
cm.createCache("vets", cacheConfiguration);
};
} }
private Configuration<Object, Object> createCacheConfiguration() { private Configuration<Object, Object> createCacheConfiguration() {
// Create a cache using infinite heap. A real application will want to use an implementation dependent // Create a cache using infinite heap. A real application will want to use an
// configuration that will better fit your needs // implementation dependent configuration that will better fit your needs
return new MutableConfiguration<>().setStatisticsEnabled(true); return new MutableConfiguration<>().setStatisticsEnabled(true);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment