开发项目中Ehcache

对EhCache的配置,我现在了解的有两种,但是我觉得这两种在我所接触到的地方却作用不大,可能是我自身技术问题,下面我具体说一下。
Ehcache主要是书写Ehcache.xml文件
在园区人才的项目中配置了三个.
<defaultCache name="com.berheley.parkrcfile.cache"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
<cache name="org.hibernate.cache.UpdateTimestampsCache"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="600"
timeToLiveSeconds="600"
overflowToDisk="false"
/>
<cache name="org.hibernate.cache.StandardQueryCache"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="600"
timeToLiveSeconds="600"
overflowToDisk="false"
/>
第一个defaultCache name="com.berheley.parkrcfile.cache"
这个缓存用于配置着spring的缓存使用的是AOP的技术来对BO层的操作进行的缓存
配置方式:
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation">
<value>classpath:ehcache.xml</value>
</property>
通过这个配置ehcache.xml的路径是存放在classpath的根目录
<bean id="methodCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
<property name="cacheManager">
<ref local="cacheManager"/>
</property>
<property name="cacheName">
<value>com.berheley.cache.METHOD_CACHE</value>
</property>
</bean>
设置EhCacheFactory,我觉得这里配置的有些问题
<property name="cacheName">
<value>com.berheley.cache.METHOD_CACHE</value>
</property>
我认为这里应该配置的是Ehcache.xml中使用的哪个Cache,应该value值为
com.berheley.parkrcfile.cache,希望大家看下对吗
<bean id="readCacheInterceptor" class="com.berheley.parkrcfile.interceptor.ReadCacheInterceptor">
<property name="cache">
<ref local="methodCache" />
</property>
</bean>
<bean id="setCacheNullInterceptor" class="com.berheley.parkrcfile.interceptor.SetCacheNullInterceptor">
<property name="cache">
<ref local="methodCache" />
</property>
</bean>
接下来使用的是AOP技术配置了两个拦截器
<bean id="readCachePointCut" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice">
<ref local="readCacheInterceptor"/>
</property>
<property name="patterns">
<list>
<value>.*getCategoryTree</value>
<value>.*queryAll</value>
</list>
</property>
</bean>
<bean id="setCacheNullPointCut" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice">
<ref local="setCacheNullInterceptor"/>
</property>
<property name="patterns">
<list>
<value>.*add</value>
<value>.*save</value>
<value>.*update</value>
<value>.*Down</value>
<value>.*delete</value>
<value>.*Up</value>

</list>
</property>
</bean>
接着配置了两个切入点的通知,拦截器的两个类是自己实现的,大致的内容为如果使用.*getCategoryTree、queryAll这两个方法则将信息放入缓存中。如果使用.*add等方法时则不使用缓存。
整个过程是这样,但是我觉得在我们的项目中凡是取得所有的值的情况大多都是valuelist完成的,那么valuelist会调用缓存吗,难道他也有queryAll这个方法吗?不解配置了这个又有什么地方会去用这些。
第二个配置hibernate的二级缓存。
第一个cache:org.hibernate.cache.UpdateTimestampsCache
第二个cache:org.hibernate.cache.StandardQueryCache
这两个是用于配置hibernate的二级缓存
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
在使用中的配置可能是这个地方,但是我不清楚希望高手能给指点下。
hibernate的二级缓存配置一直不是很清楚。
但是我在学习时发现hibernate的二级缓存需要在配置清楚后在dao里进行使用才可以,可是咱们的项目dao是统一的并没有二级缓存的使用,那么配置2级缓存起到什么作用了呢?
ps:学习中的小问题,希望大家解决。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值