111

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.

我了解timeToIdleSeconds

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

4

3 回答 3

170

timeToIdleSeconds只要在短于timeToIdleSeconds. timeToLiveSeconds无论请求多少次或何时请求,都会使缓存的对象在几秒钟后失效。

让我们这么说吧timeToIdleSeconds = 3。然后,如果 4 秒内没有请求该对象,则该对象将失效。

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

于 2010-04-06T08:36:01.547 回答
46

如果两者都设置,expirationTime则将是Math.min(ttlExpiry, ttiExpiry),其中

ttlExpiry = creationTime + timeToLive
ttiExpiry = mostRecentTime + timeToIdle

完整的源代码在这里

于 2012-02-24T10:13:57.910 回答
22

旧的 1.1 文档(可在 Google Cache 中获得,它比当前文档 AFAIK 更易于浏览且信息量更大):

timeToIdleSeconds

这是一个可选属性。

合法值是介于 0 和 Integer.MAX_VALUE 之间的整数。

这是一个元素自上次使用以来应该存在的秒数。使用意味着插入或访问。

0有一个特殊的含义,就是不检查Element空闲的时间,即永远空闲。

默认值为 0。

生存时间秒数

这是一个可选属性。

合法值是介于 0 和 Integer.MAX_VALUE 之间的整数。

它是元素自创建以来应该存在的秒数。Created 意味着使用 Cache.put 方法插入到缓存中。

0有一个特殊的含义,就是不检查Element的存活时间,即它会永远存活。

默认值为 0。

于 2011-08-12T02:08:42.613 回答