有没有使用spring来弄ehcache的呀?
我把hibernate 用spring来集成,最近看了网上一篇文章。
利用spring来缓存某类的某些方法。
原URL如下。
http://blog.csdn.net/rosen/archive/2005/01/26/269612.aspx
我的spring版本为1.2.8 hibernate 3 EHCAHE用的是hibernate自带的。
我写了这个类。
然后,配置文件如下。
<ehcache>
<diskStore path = "java.io.tmpdir"/>
<defaultCache maxElementsInMemory="10000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" />
<cache name ="com.base.methodCache" maxElementsInMemory="3000"
eternal="false" timeToIdleSeconds="5000" timeToLiveSeconds="5000"
overflowToDisk="true" />
</ehcache>
这个文件我放在了class的目录下面的。
<bean id="cacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation">
<value>/WEB-INF/classes/ehcache.xml</value>
</property>
</bean>
<bean id="methodCache"
class="org.springframework.cache.ehcache.EhCacheFactoryBean">
<property name="cacheManager">
<ref local="cacheManager" />
</property>
<property name="cacheName">
<value>com.base.methodCache</value>
</property>
</bean>
<bean id="methodCacheInterceptor"
class="com.aol.MethodCacheInterceptor">
<property name="methodCache">
<ref local="methodCache" />
</property>
</bean>
<bean id="methodCachePointCut"
class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice">
<ref local="methodCacheInterceptor" />
</property>
<property name="patterns">
<list>
<value>.*get.*</value>
</list>
</property>
</bean>
<bean id="myBean"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<bean class="com.base.service.Impl.TdCityManagerImpl"/>
</property>
<property name="interceptorNames">
<list>
<value>methodCachePointCut</value>
</list>
</property>
</bean>
上面是spring里的配置。
程序运行正常,
但是TdCityManagerImpl这个类下面的所有的方法再执行的时候,
跟本就没有缓存。
HIBERNATE还在工作。
有懂的同志帮看看。
就是缓存不上,为什么呀?