How to configure JBOSS Infinispan for using hibernate level 2 caching. I am using Spring Boot Application and Spring Data JPA is been used which has been configured to use Hibernate. My application does not have any kind of xml file.I am new to this caching.So please provide the detail solution for this.
Configure JBOSS Infinispan for using hibernate level 2 caching
1.4k views Asked by aeroboy At
2
There are 2 answers
9
On
1) make sure that hibernate-infinispan
(with transitive dependencies) is on classpath
2) set
hibernate.cache.use_second_level_cache = true
hibernate.cache.region.factory_class = org.hibernate.cache.infinispan.InfinispanRegionFactory
hibernate.cache.default_cache_concurrency_strategy = TRANSACTIONAL
javax.persistence.sharedCache.mode = ALL
You might also need to set hibernate.transaction.jta.platform
and hibernate.transaction.coordinator_class
if Spring does not do that for you automatically.
Firstly, add the dependencies to your pom.xml:
Then put this file (infinispan.xml) in your resources folder:
Add to the resources folder the file (application.properties) too:
Then you add the cache where you want, for example:
Don't forget to enable cache in your Main class:
There's also a spring boot starter for Infinispan that you can try it if you want.
Using the starter you need only set the Spring cache () in your applicationContext.xml. Create a bean of class SpringEmbeddedCacheManagerFactoryBean. Then you can annotate the classes you want with @Cacheable.
Examples here: https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-cache