I have 2 different webapps running in the same Tomcat 6 instance. Both share a library which uses hibernate for persistence. I want to enable Hibernate 2nd level caching with ehcache, but I don't want each of the webapps to have its own cache.
Any idea how I might implement this? I installed ehcache-core into $CATALINA_HOME/lib and each spring application is configuring hibernate to use ehcache like this:
<property name="hibernateProperties">
<props>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory</prop>
</props>
</property>
Both apps are using ehcache, but each still has its own distinct cache (modify an item in one app and the stale value still appears in the other app)
My ehcache.xml (also in $CATALINA_HOME/lib) looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
name="mySharedCache"
updateCheck="false" monitoring="autodetect"
dynamicConfig="false">
<diskStore path="java.io.tmpdir"/>
<defaultCache maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120">
</defaultCache
</ehcache>
More details:
- Tomcat 6
- Spring 3.0.5
- Hibernate 3.6.5
- EhCache 2.4.5