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

java - How to fill cache with new values when query cache expires : Ehcache 3 and hibernate 5 - Stack Overflow

programmeradmin3浏览0评论

I have a query cache called RatesCache to store the result of my database call of RateEntities.

I set the query cache like this for test purpose and every 30s ttl, when it expires it make a new call to database:

<cache alias="RatesCache">
    <expiry>
        <ttl unit="seconds">30</ttl>
    </expiry>
    <resources>
        <heap unit="entries">1000000</heap> 
    </resources>
    <jsr107:mbeans enable-management="true" enable-statistics="true"/>
</cache>

My rateEntity cache has a longer ttl like 12000 seconds.

My problem is whenever my query cache expires, the new result set is get BUT not stored in rateEntity cache.

The old values are still there. So when I update the database (outside of hibernate), i get the updated value when its from database each 30s but the nexts calls retrieve me the old value (the one in the entity cache) that should be replaced.

How to fix this situation, i.e clear and set the cache entity with the new result set when the ttl expires and i do the query from the database.

Thanks a lot, if you can help I'm struggling a lot since few weeks :)

PS: I tried also to make the entity cache expires before but it does n+1 call issues to database.

发布评论

评论列表(0)

  1. 暂无评论