Skip to content
Snippets Groups Projects
Commit 0b0a5904 authored by Maciej Szarlinski's avatar Maciej Szarlinski
Browse files

Externalize properties

parent 2a94e844
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import org.ehcache.config.units.EntryUnit;
import org.ehcache.expiry.Duration;
import org.ehcache.expiry.Expirations;
import org.ehcache.jsr107.Eh107Configuration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
......@@ -21,14 +22,20 @@ import java.util.concurrent.TimeUnit;
@EnableCaching
public class CacheConfig {
@Value("${vets.cache.ttl}")
private int cacheTtl;
@Value("${vets.cache.heap-size}")
private int cacheHeapSize;
@Bean
public JCacheManagerCustomizer cacheManagerCustomizer() {
return cacheManager -> {
CacheConfiguration<Object, Object> config = CacheConfigurationBuilder
.newCacheConfigurationBuilder(Object.class, Object.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(100, EntryUnit.ENTRIES))
.withExpiry(Expirations.timeToLiveExpiration(Duration.of(60, TimeUnit.SECONDS)))
.heap(cacheHeapSize, EntryUnit.ENTRIES))
.withExpiry(Expirations.timeToLiveExpiration(Duration.of(cacheTtl, TimeUnit.SECONDS)))
.build();
cacheManager.createCache("vets", Eh107Configuration.fromEhcacheCacheConfiguration(config));
};
......
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