This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes EhCache and the fly likes Difference between timeToLiveSeconds and timeToIdleSeconds. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Caching » EhCache
Bookmark "Difference between timeToLiveSeconds and timeToIdleSeconds." Watch "Difference between timeToLiveSeconds and timeToIdleSeconds." New topic
Author

Difference between timeToLiveSeconds and timeToIdleSeconds.

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Hi all, I am new to ehcache. I read that timeToLiveSeconds is the total time an entry stays in a cache region. timeToIdleSeconds is total time an entry should stay in cache if it is not referenced.

Suppose if timeToLiveSeconds is 600. Does it means after 10 minutes it will be removed from the cache? On the same object I have timeToIdleSeconds is 0. It means it is never evicted from the memory. Then according to timeToLiveSeconds property after 10 minutes it will be removed from cache. Will it be transferred to some kind of secondary cache from main cache?

I am unable to understand these properties. Can anyone please shed some light?

Thank you all in advance. Good day.


Love all, trust a few, do wrong to none.
Guillaume Jourdan
Ranch Hand

Joined: Jul 24, 2012
Posts: 47

Hello,

You can find definition on EHCache website (http://ehcache.org/documentation/2.5/configuration/configuration#dynamically-changing-cache-configuration)

timeToLive :

The maximum number of seconds an element can exist in the cache regardless of use. The element expires at this limit and will no longer be returned from the cache. The default value is 0, which means no TTL eviction takes place (infinite lifetime).

timeToIdle :

The maximum number of seconds an element can exist in the cache without being accessed. The element expires at this limit and will no longer be returned from the cache. The default value is 0, which means no TTI eviction takes place (infinite lifetime).

In fact, timeToLive of X, your element is removed from your cache after X seconds in all case and timeToIdle, your element is extended of X second if there is an access on your element before the X seconds of your first call.
Guillaume Jourdan
Ranch Hand

Joined: Jul 24, 2012
Posts: 47

In your example, if timeToLiveSeconds is 600 and timeToIdleSeconds is 0. timeToIdleSeconds is ignore and your element is removed from cache after 10 minutes.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Difference between timeToLiveSeconds and timeToIdleSeconds.