ehcache缓存问题!配置好了,就是不能缓存,搞死人啊,

本文探讨了EHCache配置及其与Hibernate结合使用时的缓存问题。通过展示ehcache.xml和hibernate.xml配置文件的具体设置,分析了为何查询结果未能有效利用缓存,每次执行都会触发数据库读取。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这是ehcache.xml文件:

<code><?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<diskStore path="java.io.tmpdir" />
<defaultCache maxElementsInMemory="10000" eternal="false"
overflowToDisk="true" timeToIdleSeconds="300" timeToLiveSeconds="180"
diskPersistent="false" diskExpiryThreadIntervalSeconds="120" />
<cache name="org.hibernate.cache.StandardQueryCache"
maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="300"
timeToLiveSeconds="4200" overflowToDisk="true" />
<cache name="org.hibernate.cache.UpdateTimestampsCache"
maxElementsInMemory="5000" eternal="true" timeToIdleSeconds="0"
timeToLiveSeconds="0" overflowToDisk="false" />
<cache name="org.yao.CopyOfJxrmBbsInfo" maxElementsInMemory="1000"
eternal="false" timeToIdleSeconds="100" timeToLiveSeconds="4200"
overflowToDisk="true" />

</ehcache>
</code>

这是hibernate.xml文件:

<code>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</property>


.
.
.
<mapping resource="org/test.hbm.xml" />
<class-cache class="org.test" usage="read-only"/>

</code>

这是测试java
<code>
Session session = HibernateSessionFactory.getSession();
try {
Query query = session.createQuery("from CopyOfJxrmBbsInfo");
query.setCacheable(true);
query.setMaxResults(10);
for(Iterator it=query.iterate();it.hasNext();){
CopyOfJxrmBbsInfo beans=(CopyOfJxrmBbsInfo) it.next();
System.out.println(beans.getId());
}

} catch (Exception e) {

}finally{
HibernateSessionFactory.closeSession();
}
</code>

他就是不缓存啊!,,,每执行一次,他都读数据库!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值