Spring: hibernate + ehcache

前端 未结 2 695
小蘑菇
小蘑菇 2021-01-02 07:38

I\'m working with a spring project using hibernate and look to implement second-level cache using ehcache. I see a number of approaches to this:

  1. spring-mod

2条回答
  •  心在旅途
    2021-01-02 08:22

    Our project uses option 3. We apply annotation org.hibernate.annotations.Cache to entities that we cache in an Ehcache, configure Ehcache using ehcache.xml, and enable and configure the Hibernate second-level cache in hibernate.cfg.xml:

        
        
            net.sf.ehcache.hibernate.EhCacheProvider
        
        
            net.sf.ehcache.hibernate.EhCacheRegionFactory
        
        true
        true
        true     
        true
    

    For most entities, we use cache concurrency strategy CacheConcurrencyStrategy.TRANSACTIONAL:

    @Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
    

    Our Maven project uses Hibernate 3.3.2GA and Ehcache 2.2.0:

        
            net.sf.ehcache
            ehcache-core
            2.2.0
        
        
            org.hibernate
            hibernate-core
            3.3.2.GA
        
        
            org.hibernate
            hibernate-commons-annotations
            3.3.0.ga
            
                
                    net.sf.ehcache
                    ehcache
                
            
        
        
            org.hibernate
            hibernate-annotations
            3.2.1.ga
        
        
            org.hibernate
            ejb3-persistence
            3.3.2.Beta1
        
    

提交回复
热议问题