jhipster-lite
jhipster-lite copied to clipboard
Module: Hibernate 2nd level cache
Configure hibernate cache manager:
@Bean
public HibernatePropertiesCustomizer hibernatePropertiesCustomizer(javax.cache.CacheManager cacheManager) {
return hibernateProperties -> hibernateProperties.put(ConfigSettings.CACHE_MANAGER, cacheManager);
}
I'll provide a PR.
We should add this by default with PostgreSQL and MySQL, right?
With any JPA/Hibernate option, when JCache is present.
There are plenty of cache configuration options between Spring and Hibernate, not sure which is the simplest one, and which is mandatory - will re-check.
any advice?
hibernate.cache.use_second_level_cache is true by default.
As it's not set to false in the generated configuration, it's currently enabled.
If you do not specify additional properties, the JCacheRegionFactory will load the default JCache provider and create the default CacheManager.
So it's simply a matter of adding hibernate-jcache dependency.
With ehcache, the above configuration is redundant in our case. The default CacheManager is used for 2nd-level caching out of the box:

However with the current caffeine implementation which is not using JCache, hibernate 2nd level caching is disabled because there is no compatible cache manager:

I can submit a new PR to upgrade Caffeine to JCache (and perhaps make it an alternative to simple cache, instead of depending on it) or do it in the same PR.
Note: instead of depending on CACHE and JPA, it should depend on JCACHE and HIBERNATE, to be exact - not big deal.
Cc @biergit as you have the opposite here https://github.com/jhipster/jhipster-lite/pull/4163/files
~~I think this PR should update some spring.jpa properties too~~
Wrong place :-p
Increasing a little bit the bounty, following the work done