About the differences between Timetoliveseconds and Timetoidleseconds in the Ehcache configuration

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.