Ehcache 3.9.2 timeToLeave and timeToIdle configuration

468 views
Skip to first unread message

wm

unread,
Jun 3, 2021, 10:41:28 AM6/3/21
to ehcache-users
Hi all,
First, I configured ehcache to use ttl and tti in java  using

ExpiryPolicy policy = ExpiryPolicyBuilder.expiry()
           .create(Duration.ofHours(6l)) // ttl
           .access(Duration.ofMinutes(30l)) //tti
           .build();

I used the above snippet in the cache configuration.
I expected that the eviction time will be Math.min(createTime + tti, createTime + ttl)
where createTime is the time when the data is inserted to the cache.
I thought the data will no longer be in the cache if not accessed for 30min once it is inserted or accessed.
However, I see that the data is still there when it is accessed repeatedly after 30 min of the time it is created. 
am i missing something here?

Secondly, is it possible in ehcache to empty the cache after sometime in a java app (without frameworks like spring, hibernate)?

Thank you in advance 
 Wonde

Chris Dennis

unread,
Jun 3, 2021, 10:55:44 AM6/3/21
to ehcach...@googlegroups.com

I would strongly recommend you don’t use TTI in Ehcache, it’s essentially deprecated: https://github.com/ehcache/ehcache3/issues/1097

 

Ehcache uses tier capacity constraints to control the size of the cache. This recent discussion may also be useful here:

https://github.com/ehcache/ehcache3/issues/2909

 

As regards emptying the cache after some time: there is no builtin support for this, but you could obviously drive this from the outside. In reality the “right” way to use Ehcache here is to set sizes on the configured tiers, and then if needed set a TTL according to how “stale” you will tolerate your data being (assuming you don’t have an externally driven invalidation process). In this (and all caching contexts) – TTL stands for “Time to Live”. Ehcache interprets this as meaning values older than the TTL will not be returned by the cache. This doesn’t mean that they will be automatically removed from the cache when they hit the TTL… we just allow them to naturally fall out when the cache eviction thresholds are hit.

 

Chris

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ehcache-users/c6f96511-65e3-4e82-9536-b997f0fabf9cn%40googlegroups.com.

Wondwosen Muhea

unread,
Jun 3, 2021, 11:15:26 AM6/3/21
to ehcach...@googlegroups.com
Thank you a lot for the feedback.
Wonde



Reply all
Reply to author
Forward
0 new messages