spring-projects / spring-projects/spring-boot
Add support for configuring Hibernate L2 Cache
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 81.5k
- Forks
- 42.7k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 65
Description
As discussed with @snicoll on Gitter, it would be nice if Spring Boot could offer an easy way to use the JCache CacheManager created by Spring Boot with the Hibernate second-level cache.
Hibernate supports different L2 caching options which can be set by e.g. using specific properties like:
spring.jpa.hibernate.cache.region.factory_class=jcache
spring.jpa.hibernate.javax.cache.provider=org.ehcache.jsr107.EhcacheCachingProvider
spring.jpa.hibernate.javax.cache.uri=classpath:ehcache3.xml
However Hibernate also supports explicitly setting the cache manager which can be done via a custom HibernatePropertiesCustomizer like:
@Configuration
public class HibernateConfig {
@Autowired
private CacheManager cacheManager;
@Bean
public HibernatePropertiesCustomizer hibernatePropertiesCustomizer() {
return hibernateProperties -> hibernateProperties.put(ConfigSettings.CACHE_MANAGER, cacheManager);
}
}
It would be nice if Spring Boot could offer a specific property like spring.jpa.hibernate.use-explicit-cache-manager, which when set to true auto configures a HibernatePropertiesCustomizer which sets the cache manager automatically?
PS: This also relates to PR #14570 adding documentation how set up Hibernate second-level caching currently.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the HibernatePropertiesCustomizer example and the listed spring.jpa.hibernate cache properties; review PR #14570 for the current documentation context. Done means an agreed configuration can make Spring Boot’s JCache CacheManager available to Hibernate’s L2 cache without the custom application bean, with the behavior documented and tested.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- backend, databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100