- What version of Ehcache you are currently using: -> 3.4
- Paste the configuration for the Cache/CacheManager you have an issue with;
- Add any name and version of other library or framework you use Ehcache with (e.g. Hibernate);
- Providing JDK and OS versions maybe useful as well.
I'm using ehcache 3.4.0 and I'm very lost at the point to "transform" cacheManager from org.ehcache.CacheManager to a org.springframework.cache.CacheManager valid One.
@Bean(name = "cacheManager")
public CacheManager cacheManager() throws URISyntaxException {
CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder().with(cluster(URI.create(props.readCacheLocation())).autoCreate()).withCache("listAllCache", newCacheConfigurationBuilder(String.class, List.class, heap(100)).withExpiry(timeToLiveExpiration(of(60, TimeUnit.SECONDS))));
PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true);
But I'm so lost when it turns to use a JCacheCacheManager and @EnableCaching/@Cacheable Annotations. I tried something like:
@Bean(name = "cacheManager")
public org.springframework.cache.CacheManager cacheManager() throws URISyntaxException {
ServerSideConfigurationBuilder serverSideConfigurationBuilder = cluster(URI.create(props.readCacheLocation())).autoCreate();
CachingProvider cachingProvider = Caching.getCachingProvider();
EhcacheCachingProvider ehcacheProvider = (EhcacheCachingProvider) cachingProvider;
DefaultConfiguration configuration = new DefaultConfiguration(ehcacheProvider.getDefaultClassLoader(), serverSideConfigurationBuilder.build());
javax.cache.CacheManager cacheManager = ehcacheProvider.getCacheManager(ehcacheProvider.getDefaultURI(), configuration);
MutableConfiguration<String, List> configuration2 = new MutableConfiguration<String, List>().setTypes(String.class, List.class).setStoreByValue(false)
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.ONE_MINUTE));
cacheManager.createCache("listAllCache", configuration2);
return new JCacheCacheManager(cacheManager);
}
but when using @EnableCaching it starts using a MalformedParametrizedTypeException that I can't understand why.
methon in Service class:
@Service
public class CountryManager {
public static final String KEY = "countryAllCache";
......
@Override
@Cacheable(value = "listAllCache", key = "#root.target.KEY")
public List<CountryRes> findAll(User user) {
return findAllTemplate(user);
}
......
}
Any help would be very nice.
Thanks in advance, Alex.