mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 12:15:50 +00:00
Merge pull request #229 from henri-tremblay:ehcacheback
* pr/229: Polish contribution Put Ehcache back
This commit is contained in:
commit
f792522b3d
3 changed files with 31 additions and 6 deletions
10
pom.xml
10
pom.xml
|
@ -79,6 +79,16 @@
|
|||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- caching -->
|
||||
<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>
|
||||
|
|
|
@ -1,14 +1,32 @@
|
|||
package org.springframework.samples.petclinic.system;
|
||||
|
||||
import javax.cache.configuration.Configuration;
|
||||
import javax.cache.configuration.MutableConfiguration;
|
||||
|
||||
import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
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 {
|
||||
|
||||
@Bean
|
||||
public JCacheManagerCustomizer cacheManagerCustomizer() {
|
||||
return cm -> {
|
||||
Configuration<Object, Object> cacheConfiguration = createCacheConfiguration();
|
||||
cm.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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,3 @@ logging.level.org.springframework=INFO
|
|||
|
||||
# Active Spring profiles
|
||||
spring.profiles.active=production
|
||||
|
||||
# Caching
|
||||
spring.cache.cache-names=vets
|
||||
|
|
Loading…
Reference in a new issue