Reputation: 101
My project is on Spring 4.3.4, Hibernate 5.2.4 and Ehcache 3.3
I am looking for a solution with a singular JSR-107 (JCache) CacheManager for the whole the application to provide:
The main concern here is Hibernate. In fact, it is a question of setting a default template for its regions. After the review of a lot of topics I have not discovered a fully suitable solution.
So, if it exists, I'm kindly ask the experts to point to it. A programmatic only way of configuring is highly appreciated (ehcache.xml is unwanted).
Added: (in answer to @Anthony Dahanne): I have already seen the solution in the project you are pointing for before I posted this topic. Even more, this project was the starting point of my investigation week ago.
But that solution is involving the explicit declaration of several named Cache regions not only for Spring, but even for Hibernate, as we can find in the CacheConfiguration#createCacheConfigurations method.
This is inconvenient in a real project which contains 100500 different Entities, NaturalKeys and so on, which are managed by Hibernate, because for all them it should create appropriate regions on the fly. I distinct the main power of Hibernate's RegionFactory as an ability to do this magic work automatically. But what we see in the pointed project in the customized JCacheRegionFactory class? The direct ban for it to generate new regions, which is implemented by means of unconditional exception that will be thrown on any attempt to do that (it is even noted with the "...but makes sure all caches are already existing to prevent spontaneous creation of badly configured caches..." comment).
The ideal solution must be able to set up a sole "default template" (on the CacheManager level) just like it works in case of encache.xml (...jcache:defaults default-template="myDefaultTemplate...), ...but without xml.
Upvotes: 4
Views: 3801
Reputation: 5731
We never want the default configuration (aka new MutableConfiguration
). However, setting a meaningful default is acceptable. So indeed, in your case I would use a customized JCacheRegionFactory
.
See this article about it.
Upvotes: 1
Reputation: 5053
There is a JHipster fullstack demo example on ehcache3-samples github repo
This example is based on Spring boot programmatically sets up an ehcache3 cache, exposing it as a JSR-107 CacheManager
This cache is used in conjunction with Hibernate and also independently.
Upvotes: 2