When using the Ehcache framework, the two properties of Timetoliveseconds and Timetoidleseconds are easy to confuse and can be recorded today when you are free, in case you forget again.
Let's start by explaining what these two properties do: (Of course, these 2 properties are only valid if Eternal is false)
Timetoliveseconds-When an object has been cached for more than the Timetoliveseconds property value, the object expires and Ehcache will clear it from the cache , which is the maximum amount of time that the cache can survive from its creation date, in seconds (s)
Timetoidleseconds-When the object has been idle for more than the Timetoidleseconds property value since the last time it was accessed, the object expires, and Ehcache will empty it from the cache, that is, after the cache is created, The interval between the last access time and the cache failure, in seconds (s)
What do you mean?
Now suppose you have the following configuration:
Timetoidleseconds=60
timetoliveseconds=180
When a data is added to the cache, the data can survive in the cache for a maximum of 180 seconds (timetoliveseconds), and in 180 seconds, assuming that the data is fetched more than once in the cache, the time interval of 2 consecutive fetches of data is less than 60 seconds ( Timetoidleseconds), the data can be obtained successfully, but if the last fetch is more than 60 seconds past the next fetch, then NULL will be obtained because the data has been moved out of the cache at this time.
Moreover, timetoliveseconds must be greater than timetoidleseconds to make sense.
About the differences between Timetoliveseconds and Timetoidleseconds in the Ehcache configuration