Ehcache isn't working properly in my project. I run grails 3.3.1 "with org.grails.plugins:cache-ehcache:3.0.0.M1" and since i dont know where to put the ehcache.xml file and how the file should look like i tried to configure ehcache programmaticially
I created a cacheService with a methode "initCaches" which i run from my bootstrap.groovy
class CacheService {
void initCaches() {
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withCache("sevenSeconds", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10))
.withExpiry(Expirations.timeToLiveExpiration(Duration.of(7, TimeUnit.SECONDS)))
)
.withCache("twentySeconds", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10))
.withExpiry(Expirations.timeToLiveExpiration(Duration.of(20, TimeUnit.SECONDS)))
)
.build()
cacheManager.init()
}
}
When I start the application the console says that the caches have been created:
2018-06-26 15:47:31.302 INFO --- [ main] org.ehcache.core.EhcacheManager : Cache 'sevenSeconds' created in EhcacheManager.
2018-06-26 15:47:31.310 INFO --- [ main] org.ehcache.core.EhcacheManager : Cache 'twentySeconds' created in EhcacheManager.
Now I access a service method which is annotated with @Cacheable("sevenSeconds") and there comes the part which is confusing me: Again the console says, that the cache has been created (instead of putting the result into the old already out of CacheService created one):
2018-06-26 15:47:31.302 INFO --- [ main] org.ehcache.core.EhcacheManager : Cache 'sevenSeconds' created in EhcacheManager.
If i access the service again with same parameters a cached result will returned BUT the timeToLive is NOT 7 seconds like I created the cache in my CacheService.
It looks like @Cacheable doesn't consider my created caches in CacheService
Does anybody know what I am doing wrong?
thx