Map eviction, time-to-live and max-idle

1,041 views
Skip to first unread message

Mikael Ståldal

unread,
Oct 30, 2014, 12:39:58 PM10/30/14
to haze...@googlegroups.com
If you use IMap.set(K key, V value, long ttl, TimeUnit timeunit), will the entry be evicted
a) X seconds after first put into the map, or 
b) X seconds after last updated?

If (a), is there any way to get the (b) behavior?


What about time-to-live and max-idle in map-config? The documentation is slightly vague:

time-to-live: Maximum time in seconds for each entry to stay in the map. If it is not 0, entries that are older than and not updated for this time are evicted automatically. Valid values are integers between 0 and Integer.MAX VALUE. Default value is 0 and it means infinite. Moreover, if it is not 0, entries are evicted regardless of the set eviction-policy.

max
-idle-seconds: Maximum time in seconds for each entry to stay idle in the map. Entries that are idle for more than this time are evicted automatically. An entry is idle if no get, put or containsKey is called. Valid values are integers between 0 and Integer.MAX VALUE. Default value is 0 and it means infinite.

I guess this mean that the time-to-live property will evict entries X seconds after last updated? And max-idle will evict entries X seconds after last updated or fetched? (I assume that put(), replace() and set() count as update, and the asynchronous versions as well.)


What will happen if you mix these map-config properties with IMap.set(K key, V value, long ttl, TimeUnit timeunit)?


Ahmet Mircik

unread,
Oct 30, 2014, 12:49:44 PM10/30/14
to haze...@googlegroups.com

Hi Mikael,

Behavior is (a).

Max-idle works against last-access-time.

If you mix ttl & max-idle, entry will be evicted according to nearest one in time.

Some more details here: https://github.com/hazelcast/hazelcast/issues/3920


--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/b4758ad6-c001-4bb6-a28b-9d5af479f5d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mikael Ståldal

unread,
Oct 30, 2014, 12:59:37 PM10/30/14
to haze...@googlegroups.com
So how can I get expiration after latest update? Do I have to use IMap.set() and specify longer TTL value for each update operation? What if I want to use IMap.replace()?

Ahmet Mircik

unread,
Oct 31, 2014, 5:06:02 AM10/31/14
to haze...@googlegroups.com

If it fits in your use case, using max-idle seems a better option instead of extending TTL in every set operation.

replace updates last-access-time and only affects max-idle expiration, nothing to do with TTL


Mikael Ståldal

unread,
Oct 31, 2014, 9:42:37 AM10/31/14
to haze...@googlegroups.com
I don't think that map-config is dynamic enough for my use case.

BTW, why are there no variants of replace() with TTL parameters?

Ahmet Mircik

unread,
Oct 31, 2014, 10:47:46 AM10/31/14
to haze...@googlegroups.com
Some reasons;

Reply all
Reply to author
Forward
0 new messages