首页 新闻 会员 周边

spring+mybatis+ehcache 缓存配置问题

0
[已关闭问题] 关闭于 2016-10-25 16:56

使用ehcache 作为mybatis的缓存,发现即使查询时传的参数变动了,还是从之前的缓存中读取,不根据新的查询条件进行查询,导致查询出的数据不正确,如何解决

配置如下:

<!-- 开启spring缓存 -->
	<cache:annotation-driven cache-manager="cacheManager" />
	<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
		<property name="configLocation" value="classpath:ehcache/ehcache-shiro.xml"/>
		<property name="shared" value="true"></property>
	</bean>
	<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" >
		<property name="cacheManager" ref="cacheManagerFactory"/>
	</bean>

	<!-- 用户授权信息Cache, 采用EhCache -->
	<bean id="shiroEhcacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
		<property name="cacheManager" ref="cacheManagerFactory" />
		<!--<property name="cacheManagerConfigFile" value="classpath:ehcache/ehcache-shiro.xml"/>-->
	</bean>

 

 

ehcache-shiro.xml配置如下

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
         updateCheck="false">
    <diskStore path="java.io.tmpdir" />
    <defaultCache eternal="false" maxElementsInMemory="1000"
                  overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
                  timeToLiveSeconds="600" memoryStoreEvictionPolicy="LRU" />
    <cache name="baseCache" eternal="false" maxElementsInMemory="100"
           overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
           timeToLiveSeconds="300" memoryStoreEvictionPolicy="LRU" />
</ehcache>

 

 

mybatis-mapper.xml中加了如下配置:

<cache type="org.mybatis.caches.ehcache.LoggingEhcache" >
		<property name="timeToIdleSeconds" value="3600"/>
		<property name="timeToLiveSeconds" value="3600"/>
		<property name="maxEntriesLocalHeap" value="1000"/>
		<property name="maxEntriesLocalDisk" value="10000000"/>
		<property name="memoryStoreEvictionPolicy" value="LRU"/>
	</cache>

 

 

求帮助

烟雨凌的主页 烟雨凌 | 初学一级 | 园豆:197
提问于:2016-10-25 16:56
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册