最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Configuring TTL for hibernate query cache - Stack Overflow

programmeradmin1浏览0评论

I don't want to rely upon the default TTL of 1 hour provided by hibernate so I am configuring custom TTL for my hibernate query cache region.

My application is using hibernate on DAO level and we are using hazelcast in client server mode as second level cache provider for hibernate.

This is how I am using the hibernate query cache - refer below code snippet

Criteria criteria = getSession().createCriteria(MyClass.java);
criteria.setCacheable(true);
criteria.setCacheRegion("my.query.cache.region");
criteria.list();

Below is the hibernate configuration -

<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.use_query_cache">true</property>

Below is the map config for "my.query.cache.region" in hazelcast.xml residing on hazelcast server

<map name="default">
   <time-to-live-seconds>180</time-to-live-seconds>
</map>

After doing all this I am checking the stats of the "my.query.cache.region"

getSession().getSessionFactory().getStatistics().getSecondLevelCacheStatistics("my.query.cache.region")

I am observing that 180 seconds ~ 3 mins of TTL is not having any impact, the cache is expiring after an hour only - means picking the default hibernate TTL of 1 hour.

Please guide me where i am going wrong. how can i configure the TTL for hibernate query cache regions?

发布评论

评论列表(0)

  1. 暂无评论