如何区分ehcache中的生存时间和空闲时间

Jac*_*ine 99 java ehcache

关于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.
Run Code Online (Sandbox Code Playgroud)

我理解timeToIdleSeconds

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

Bor*_*vić 149

timeToIdleSeconds只要在短于的时间内请求缓存对象,就可以使缓存对象保持在timeToIdleSeconds.timeToLiveSeconds无论多少次或何时请求,都会使缓存的对象在该秒后失效.

我们这样说吧timeToIdleSeconds = 3.如果4秒钟内没有请求对象,则该对象将失效.

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

  • 作为第一评论的后续行动(由@JacquesRenéMesrine撰写).对于TTL和TTI设置(即大于零)的情况:1)TTI> = TTL:TTI*无效*.在`creationTime + TTL`之后,条目被认为是_expired_ 2)TTI <TTL:在min((max(lastAccessTime,creationTime)+ TTI),(creationTime + TTL)之后,条目被认为是_expired_) (8认同)
  • @Gayathri如果您有一个经常访问的数据项(每两秒钟),但TTL为60秒.即使连续访问(从不闲置),它仍然会每六十秒从源头拉出一次. (3认同)
  • 所以我想我们总是想设置 idletime &lt; ttl (2认同)

Lee*_*iam 40

如果你设置两者,那expirationTime将是Math.min(ttlExpiry, ttiExpiry),在哪里

ttlExpiry = creationTime + timeToLive
ttiExpiry = mostRecentTime + timeToIdle
Run Code Online (Sandbox Code Playgroud)

这里有完整的源代码.


Dam*_*amo 22

旧的1.1文档(可在Google Cache中获取,比当前文档AFAIK更易于浏览和提供更多信息):

timeToIdleSeconds

这是一个可选属性.

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

它是Element自上次使用以来应该生存的秒数.使用的意思是插入或访问.

0具有特殊含义,不检查Element的空闲时间,即它将永远空闲.

默认值为0.

timeToLiveSeconds

这是一个可选属性.

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

它是元素自创建以来应该生存的秒数.创建使用Cache.put方法插入缓存的方法.

0具有特殊含义,不检查Element的生存时间,即它将永远存在.

默认值为0.