Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has Anyone Gotten Hibernate to Use Elasticache as its 2nd Level Cache?

I found some threads saying this was doable, but did not find specific instructions or config information.

I want to do this from Beanstalk as well: the app should get deployed to beanstalk with a config that points hibernate to the elasticache instance(s).

like image 646
Rob Avatar asked Jan 06 '12 23:01

Rob


People also ask

Do you want to use Hibernate 2nd level cache?

Why Is a Second-Level Cache Important for Hibernate? A second-level cache improves application performance with regard to persistence for all sessions created with the same session factory.

Which 2nd level cache is better in hibernate?

Hibernate second level cache uses a common cache for all the session object of a session factory. It is useful if you have multiple session objects from a session factory. SessionFactory holds the second level cache data. It is global for all the session objects and not enabled by default.

Which cache is best for hibernate?

Hibernate 2nd level cache is best suitable for data that rarely or never changes. However since hibernate provides a generalized caching provider implemented by multiple caching solutions, it limits usability of features provided by caching solutions.


1 Answers

Yes, we were able to configure hibernate with 2nd level cache.. Not with beanstalk though.. This code should help you with it.

<props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.format_sql">false</prop>


            <prop key="hibernate.generate_statistics">true</prop>
            <prop key="hibernate.cache.use_structured_entries">true</prop>
            <!-- prop key="hibernate.hbm2ddl.auto" >update</prop -->
            <prop key="hibernate.jdbc.batch_size">100</prop>


            <prop key="hibernate.cache.provider_class">com.googlecode.hibernate.memcached.MemcachedCacheProvider
            </prop>
            <!-- Cache disabled -->
            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.cache.use_second_level_cache">true</prop>
            <prop key="hibernate.memcached.servers"><elasticachehostname>:11211</prop>
            <prop key="hibernate.memcached.cacheTimeSeconds">300</prop>



            <prop key="hibernate.memcached.connectionFactory">DefaultConnectionFactory</prop>
            <prop key="hibernate.memcached.clearSupported">false</prop>


        </props>

You would need the hibernate memcached jar as well

like image 88
Anoop Halgeri Avatar answered Sep 22 '22 17:09

Anoop Halgeri