如何在ehcache中区分时间和时间?

时间:2021-07-21 20:24:21

The docs on ehache says:

ehache的医生说:

timeToIdleSeconds: Sets the time to idle for an element before it expires.
i.e. The maximum amount of time between accesses before an element expires

timeToLiveSeconds: Sets the time to live for an element before it expires.
i.e. The maximum time between creation time and when an element expires.

I understand timeToIdleSeconds

我理解timeToIdleSeconds

But does it means that after the creation & first access of a cache item, the timeToLiveSeconds is not applicable anymore ?

但是,这是否意味着在创建和首次访问缓存项之后,timeToLiveSeconds不再适用?

3 个解决方案

#1


131  

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.

timeToIdleSeconds允许将缓存的对象保存在比timeToIdleSeconds更短的时间段内,只要它被请求。timeToLiveSeconds将使缓存的对象在数秒之后失效,不管它需要多少次或何时被请求。

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

我们设timeToIdleSeconds = 3。然后,如果对象4秒内没有被请求,则该对象将无效。

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.

如果timeToLiveSeconds = 90,那么该对象将在90秒后从缓存中删除,即使在其短暂生命的第90秒被请求了几毫秒。

#2


34  

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

如果你同时设置了这两个,那么到期时间就是数学了。min(ttlExpiry ttiExpiry)

ttlExpiry = creationTime + timeToLive
ttiExpiry = mostRecentTime + timeToIdle

Full source code here.

完整的源代码。

#3


21  

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

从旧的1.1文档中(可以在谷歌缓存中获得,它比当前的docs AFAIK更容易浏览和提供更多信息):

timeToIdleSeconds

timeToIdleSeconds

This is an optional attribute.

这是一个可选属性。

Legal values are integers between 0 and Integer.MAX_VALUE.

法律值是0和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.

0有一个特殊的含义,即不检查元素的空闲时间,也就是说它将永远闲置。

The default value is 0.

默认值是0。

timeToLiveSeconds

timeToLiveSeconds

This is an optional attribute.

这是一个可选属性。

Legal values are integers between 0 and Integer.MAX_VALUE.

法律值是0和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.

0有一个特殊的含义,就是不检查元素的时间来生存,也就是说它将永远存在。

The default value is 0.

默认值是0。

#1


131  

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.

timeToIdleSeconds允许将缓存的对象保存在比timeToIdleSeconds更短的时间段内,只要它被请求。timeToLiveSeconds将使缓存的对象在数秒之后失效,不管它需要多少次或何时被请求。

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

我们设timeToIdleSeconds = 3。然后,如果对象4秒内没有被请求,则该对象将无效。

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.

如果timeToLiveSeconds = 90,那么该对象将在90秒后从缓存中删除,即使在其短暂生命的第90秒被请求了几毫秒。

#2


34  

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

如果你同时设置了这两个,那么到期时间就是数学了。min(ttlExpiry ttiExpiry)

ttlExpiry = creationTime + timeToLive
ttiExpiry = mostRecentTime + timeToIdle

Full source code here.

完整的源代码。

#3


21  

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

从旧的1.1文档中(可以在谷歌缓存中获得,它比当前的docs AFAIK更容易浏览和提供更多信息):

timeToIdleSeconds

timeToIdleSeconds

This is an optional attribute.

这是一个可选属性。

Legal values are integers between 0 and Integer.MAX_VALUE.

法律值是0和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.

0有一个特殊的含义,即不检查元素的空闲时间,也就是说它将永远闲置。

The default value is 0.

默认值是0。

timeToLiveSeconds

timeToLiveSeconds

This is an optional attribute.

这是一个可选属性。

Legal values are integers between 0 and Integer.MAX_VALUE.

法律值是0和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.

0有一个特殊的含义,就是不检查元素的时间来生存,也就是说它将永远存在。

The default value is 0.

默认值是0。