Hello All,
I am trying to enable EHCahce for my spring-hibernate app running in a web applicaiton. I am using Spring 1.1.3 and Hibernate 2.1.
It appears that the cache is not intercepting and caching my database calls as there seems to be no reduction in the SQL displayed to the console.
What are the steps to enable the cache with spring?
Here is what I have done so far....
added the below to my hibernate context file inside the sessionFactory configuration.
Created an EHCache.xml file ...Code:<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"> <property name="dataSource"><ref bean="topupDataSource"/></property> <property name="mappingResources"> <list> <value>com/macalla/topup/model/Order.hbm.xml</value> ... left out for space reasons <value>com/macalla/topup/model/VCustomerSearch.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">net.sf.hibernate.dialect.OracleDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.use_outer_join">false</prop> <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.Provider</prop> <prop key="hibernate.hibernate.cache.use_query_cache">true</prop> </props> </property> </bean>
I have also added the cache element to the mapping files. I am aware jcs is deprecated, but im using XDoclaet tags to generate stuff so this is a segment from my mapping file. I am sure that ehcache still supports this tag anyhow.Code:<ehcache> <diskStore path="java.io.tmpdir"/> <!-- ehcache requires a default cache --> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" /> <!-- The SystemValue Cache: cached for 2 hrs (7200 secs) --> <cache name="com.macalla.topup.model.SystemValue" maxElementsInMemory="100" eternal="false" timeToIdleSeconds="7200" timeToLiveSeconds="7200" overflowToDisk="false" /> <!-- The TransPaymentState Cache: cached for infinity --> <cache name="com.macalla.topup.model.TransPaymentState" maxElementsInMemory="100" eternal="false" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" /> <!-- Standard Qurey Cache --> <cache name="net.sf.hibernate.cache.StandardQueryCache" maxElementsInMemory="5" eternal="false" timeToLiveSeconds="120" overflowToDisk="false"/> ETC ETC ETC </ehcache>
Any other steps I need to do?? Do I need to create an spring managed instance of the cache manager and inject it to some component?Code:<jcs-cache usage="read-write" />
I am aware of the change in the providor class for EHCache in hibernate as of version 2.1.8, but I think my version of Hibernate is pre-2.1.8, and at any rate I get an instantiation error if I try to use the new class.
Any help appreciated. Thanks
Colm


Reply With Quote