jhipster-lite icon indicating copy to clipboard operation
jhipster-lite copied to clipboard

Module: Hibernate 2nd level cache

Open pblanchardie opened this issue 3 years ago • 2 comments

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.

pblanchardie avatar Jan 12 '22 16:01 pblanchardie

We should add this by default with PostgreSQL and MySQL, right?

pascalgrimaud avatar Jan 12 '22 17:01 pascalgrimaud

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?

pblanchardie avatar Jan 13 '22 10:01 pblanchardie

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:

image

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

image

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.

pblanchardie avatar Nov 07 '22 03:11 pblanchardie

Cc @biergit as you have the opposite here https://github.com/jhipster/jhipster-lite/pull/4163/files

DamnClin avatar Nov 07 '22 06:11 DamnClin

~~I think this PR should update some spring.jpa properties too~~

Wrong place :-p

pascalgrimaud avatar Nov 07 '22 06:11 pascalgrimaud

Increasing a little bit the bounty, following the work done

pascalgrimaud avatar Apr 12 '23 15:04 pascalgrimaud