How to differentiate between time to live and time to idle in ehcache How to differentiate between time to live and time to idle in ehcache java java

How to differentiate between time to live and time to idle in ehcache


timeToIdleSeconds enables cached object to be kept in as long as it is requested in periods shorter than timeToIdleSeconds. timeToLiveSeconds will make the cached object be invalidated after that many seconds regardless of how many times or when it was requested.

Let's say that timeToIdleSeconds = 3. Then the object will be invalidated if it hasn't been requested for 4 seconds.

If timeToLiveSeconds = 90, then the object will be removed from cache after 90 seconds, even if it has been requested few milliseconds in the 90th second of its short life.


If you set both, the expirationTime will be Math.min(ttlExpiry, ttiExpiry), where

ttlExpiry = creationTime + timeToLivettiExpiry = mostRecentTime + timeToIdle

Full source code here.


From the old 1.1 documentation (available in Google Cache, which is easier to browse and more informative than the current docs AFAIK):

timeToIdleSeconds

This is an optional attribute.

Legal values are integers between 0 and Integer.MAX_VALUE.

It is the number of seconds that an Element should live since it was last used. Used means inserted or accessed.

0 has a special meaning, which is not to check the Element for time to idle, i.e. it will idle forever.

The default value is 0.

timeToLiveSeconds

This is an optional attribute.

Legal values are integers between 0 and Integer.MAX_VALUE.

It is the number of seconds that an Element should live since it was created. Created means inserted into a cache using the Cache.put method.

0 has a special meaning, which is not to check the Element for time to live, i.e. it will live forever.

The default value is 0.