5
在我的查询(查找)获得缓存会话关闭后,在新会话中,在我通过随机写入Sql查询更改数据库后,hibernate会逐出所有内容,我该如何阻止发生?我正在研究为很少改变的事情制定政策。ehcache hibernate第二级缓存,hibernate自动排除
INFO Executing [namedSqlQuery=dao.web_login, objs=[user1]]
DEBUG org.springframework.orm.hibernate3.SessionFactoryUtils user1- Opening Hibernate Session
DEBUG org.hibernate.impl.SessionImpl user1 - opened session at timestamp: 5511432318976000
DEBUG org.hibernate.impl.SessionFactoryImpl user1- evicting second-level cache: USERS_LOOKUP
DEBUG org.hibernate.impl.SessionFactoryImpl user1- evicting second-level cache: COUNTRY_LOOKUP
ecache.xml
<cache name="query.oneHourPolicy"
maxElementsInMemory="10000"
eternal="false"
timeToLiveSeconds="3600"
diskPersistent="true"
overflowToDisk="true"/>
弹簧hibernate配置
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop>
<prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml</prop>
您的CacheMode设置为REFRESH(即CacheMode.REFRESH) – Santosh
不,我写了一个junit类来在同一个会话中运行相同的查询,但没有随机SQL,它从20秒到1秒才得到答复 – Rodriguez
JUnit log 0st time - 20134 ms 1st time - 207 ms第2次 - 183 ms第3次 - 179 ms第4次 - 185 ms运行随机sql查询第5次 - 20043 ms第6次 - 182 ms第7次 - 181 ms第8次 - 177 ms第9次 - 179 ms – Rodriguez