Infinispan namedCache到期

时间:2014-02-28 15:21:14

标签: java caching jboss7.x infinispan

我正在测试jboss 7上托管的infinispan中的命名缓存的配置设置。我正在使用REST服务器API实现,以便我可以从任何地方访问缓存。这是我的配置文件。

<infinispan>
    <namedCache name="keydata">
        <!-- http://infinispan.org/docs/5.2.x/user_guide/user_guide.html#_expiration_2 -->
        <expiration lifespan="1000" reaperEnabled="true" />
    </namedCache>
</infinispan>

现在一切正常,实例启动并创建了缓存。我可以使用REST API将新条目推送到此命名缓存。我的问题是它们似乎永远不会过期。看起来默认情况下收割机会每隔60秒唤醒,因为我在日志中看到它时会发生这种情况:

09:15:05,920 TRACE [EvictionManagerImpl] (Scheduled-eviction-thread-0)
    Purging data container of expired entries
09:15:05,920 TRACE [EvictionManagerImpl] (Scheduled-eviction-thread-0)
    Purging data container completed in 0 milliseconds

如果我随后使用GET命中服务器,则会返回缓存的值。这是我做的时候的痕迹。

09:17:10,451 TRACE [InvocationContextInterceptor] (http-localhost/127.0.0.1:8280-1) 
    Invoked with command GetKeyValueCommand {key=user123, flags=null} and 
    InvocationContext [org.infinispan.context.SingleKeyNonTxInvocationContext@2b77b3f2]
09:17:10,451 TRACE [EntryFactoryImpl] (http-localhost/127.0.0.1:8280-1)
    Exists in context? null 
09:17:10,451 TRACE [EntryFactoryImpl] (http-localhost/127.0.0.1:8280-1)
    Retrieved from container ImmortalCacheEntry{key=user123, value=ImmortalCacheValue
    {value=org.infinispan.remoting.MIMECacheEntry@90c3ab46}}
09:17:10,451 TRACE [CallInterceptor] (http-localhost/127.0.0.1:8280-1)
    Executing command: GetKeyValueCommand {key=user123, flags=null}.
09:17:10,451 TRACE [GetKeyValueCommand] (http-localhost/127.0.0.1:8280-1)
    Found value org.infinispan.remoting.MIMECacheEntry@90c3ab46

我会继续挖掘,但我很好奇。有没有人遇到过这个?为什么具有已定义生命周期的命名缓存会插入ImmortalCacheEntry条目?

在有人建议之前,如果你看一下我在上面的XML配置文件中提到的文档,就会出现拼写错误。了解XML标记上属性的真实拼写的唯一方法是直接查看org.infinispan.configuration.parsing.Parser52类的源。

谢谢!

编辑:

我正在挖掘infinispan源代码,并在org.infinispan.container.InternalEntryFactoryImpl中看到这一点:

@Override
public InternalCacheEntry create(Object key, Object value, EntryVersion ignored, long lifespan, long maxIdle) {
    if (lifespan < 0 && maxIdle < 0) return new ImmortalCacheEntry(key, value);
    if (lifespan > -1 && maxIdle < 0) return new MortalCacheEntry(key, value, lifespan);
    if (lifespan < 0 && maxIdle > -1) return new TransientCacheEntry(key, value, maxIdle);

    return new TransientMortalCacheEntry(key, value, maxIdle, lifespan);
}

VersionedInternalEntryFactoryImpl看起来是一样的。我知道这是我的生命价值,所以给出了什么?大脑......伤害......

编辑2:

我刚注意到一些有趣的事情。当我创建条目时,我看到了:

09:46:49,639 TRACE [EntryFactoryImpl] (http-localhost/127.0.0.1:8280-1)
    Creating new entry.
09:46:49,639 TRACE [CallInterceptor] (http-localhost/127.0.0.1:8280-1)
    Executing command: PutKeyValueCommand{key=user123,
    value=org.infinispan.remoting.MIMECacheEntry@90c3ab46, flags=null,
    putIfAbsent=false, lifespanMillis=-1000, maxIdleTimeMillis=-1000, successful=true}.

看起来毕竟没有获得我的生命值......

编辑3:

我想扩展我以前的编辑。经过一些代码之后,看起来跟踪中的那些值来自REST API服务请求。通过向PUT / POST请求添加特定标头,可以覆盖命名高速缓存上的lifespan和maxIdle值。由于我没有使用这些可选参数,因此它们显示在跟踪中,默认值为-1秒,后者将转换为毫秒。

http://infinispan.org/docs/5.2.x/user_guide/user_guide.html#_headers

也许更令人沮丧的是,如果我在PUT请求中传递可选覆盖,它就可以了!我似乎无法追查为什么忽略此设置。我知道它正在被正确解析,因为如果我拼错它,缓存配置构建器会对我大喊大叫。

当然,我可以使用可选的覆盖来设置这种行为,但还有其他的东西会神秘地使用REST服务器吗?

是的......我仍然被卡住了。

1 个答案:

答案 0 :(得分:1)

我不知道在初次搜索中我是如何错过这一点的,但我在另一个SO问题中找到了答案。

infinispan cache server expiration failure