为了账号安全,请及时绑定邮箱和手机立即绑定

Hibernate4 + Ehcache 配置问题

标签:
Java

4.0配置如下:
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
3.3配置如下:
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="cache.provider_class ">org.hibernate.cache.EhCacheProvider</property>

一直不理解ehcache中 timeToIdleSeconds和 timeToLiveSeconds 这两个配置的区别,特意找到官方文档看了一下,基本理解了它的意思。
首先看一段原文:

What is the difference between TTL, TTI, and eternal?
These are three cache attributes that can be used to build an effective eviction configuration.
It is advised totest and tune these values to help optimize cache performance.
TTI timeToIdleSeconds is the maximumnumber of seconds that an element can exist in the cache without being accessed,
while TTL timeToLiveSeconds is the maximum number of seconds that an element can exist in the cache whether or not is has been accessed.
If the eternal flag is set, elements are allowed to exist in the cache eternallyand none are evicted.
The eternal setting overrides any TTI or TTL settings. These attributes are set for the entire cache in the configuration file. If you want to set them per element, you must do it programmatically

主要意思:

1.TTI timeToIdleSeconds is the maximum number of seconds that an element can exist in the cache without being accessed:
TTI用于设置对象在cache中的最大闲置时间,就是 在一直不访问这个对象的前提下,这个对象可以在cache中的存活时间。
2.TTL timeToLiveSeconds is the maximum number of seconds that an element can exist in the cache whether
or not is has been accessed.
TTL用于设置对象在cache中的最大存活时间,就是 无论对象访问或是不访问(闲置),这个对象在cache中的存活时间。
3.If the eternal flag is set, elements are allowed to exist in the cache eternally and none are evicted。
当配置了 eternal ,那么TTI和TTL这两个配置将被覆盖,对象会永恒存在cache中,永远不会过期。

点击查看更多内容
3人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
JAVA开发工程师
手记
粉丝
168
获赞与收藏
3550

关注作者,订阅最新文章

阅读免费教程

感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消