I'm stuck finding solution how to implement EhCache3 with Spring Boot 2. The problem is that in version 3 they changed package to org.ehcache and examples of xml-less configuration I found are for 2 version where you declare net.sf.ehcache.config. and I want to work with 3rd version.
package com.jcg.example.ehcache_no_xml.config;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import net.sf.ehcache.Cache;
import net.sf.ehcache.config.CacheConfiguration;
@Configuration
public class EhCacheConfig {
@Bean
public EhCacheManagerFactoryBean cacheManager() {
return new EhCacheManagerFactoryBean();
}
@Bean
public EhCacheCacheManager testEhCacheManager() {
// testEhCache Configuration - create configuration of cache that previous required XML
CacheConfiguration testEhCacheConfig = new CacheConfiguration()
.eternal(false) // if true, timeouts are ignored
.timeToIdleSeconds(3) // time since last accessed before item is marked for removal
.timeToLiveSeconds(5) // time since inserted before item is marked for removal
.maxEntriesLocalHeap(10) // total items that can be stored in cache
.memoryStoreEvictionPolicy("LRU") // eviction policy for when items exceed cache. LRU = Least Recently Used
.name("testCache");
Cache testCache = new Cache(testEhCacheConfig);
cacheManager().getObject().addCache(testCache);
return new EhCacheCacheManager(cacheManager().getObject());
}
}
Is there any solution ho to create ehCache configuration propramaticaly with spring?