Rod*_*uez 5 java spring caching hibernate ehcache
在我的查询(查找)得到缓存会话关闭之后,在新会话中,hibernate在通过随机写入Sql Query更改数据库之后驱逐所有内容,我该如何阻止它发生?我正在考虑为很少改变的事情制定政策.
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
Run Code Online (Sandbox Code Playgroud)
ecache.xml
<cache name="query.oneHourPolicy"
maxElementsInMemory="10000"
eternal="false"
timeToLiveSeconds="3600"
diskPersistent="true"
overflowToDisk="true"/>
Run Code Online (Sandbox Code Playgroud)
spring 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>
Run Code Online (Sandbox Code Playgroud)
发现 Hibernate 问题https://hibernate.onjira.com/browse/HHH-2224
我用下面的测试:
在我的随机查询中
<sql-query name="random_write_query" callable="false">
<synchronize table="USER"/>
<synchronize table="USER_ADDRESS"/>
{CALL PACKAGE.FUNCTION(?)}
</sql-query>
Run Code Online (Sandbox Code Playgroud)
每当我调用上面的内容并且它是数据库更改时,它只会使由 table = USER 或 USER_ADDRESS 同步的缓存无效
并且只有同步的随机读取查询或实体才会被驱逐
<sql-query name="random_read_query">
<synchronize table="USER"/>
<synchronize table="USER_ADDRESS"/>
<return-scalar column="USERNAME" type="string"/>
<![CDATA[
SELECT USERNAME FROM USER, USER_ADDRESS...
]]>
</sql-query>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
810 次 |
| 最近记录: |