Question

I am testing configuration settings for a named cache in infinispan hosted on jboss 7. I am using the REST server API implementation so that I can access the cache from anywhere. Here is my configuration file.

<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>

Now everything appears to be fine, the instance starts up and my cache is created. I can use the REST API to push new entries to this named cache. My problem is that they never seem to expire. It looks like the reaper wakes up every 60 seconds by default as I see this in my logs when it happens:

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

If I then hit the server with a GET, the cached value comes back. Here is the trace when I do that.

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

I'll continue digging, but I'm curious. Has anyone come across this before? Why would a named cache with a defined lifespan insert ImmortalCacheEntry entries?

Before anyone suggests it, if you do look at the docs that I mentioned in the XML config file above, there are spelling mistakes. The only way to know the true spelling of the attributes on the XML tags is to look directly at the source of org.infinispan.configuration.parsing.Parser52 class.

Thanks!

EDIT:

I am digging through infinispan source code and see this in the 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);
}

The VersionedInternalEntryFactoryImpl looks the same. I know it's getting my lifespan value, so what gives? Brain... hurts...

EDIT 2 :

I just noticed something interesting. When I created the entry, I see this:

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}.

Looks like it isn't getting my lifespan value after all...

EDIT 3:

I want to expand on my previous edit. After some more slogging through the code, it looks like those values in the trace are from the REST API service request. It is possible to override the lifespan and maxIdle values on the named cache by adding specific headers to the PUT/POST request. Since I am not using those optional parameters they are showing up in the trace with the default value of -1 seconds, which is converted to milliseconds later.

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

Perhaps even more frustratingly, if I pass in the optional override on the PUT request, it works! I can't seem to track down why this setting is ignored. I know it is getting parsed properly because if I misspell it, the cache configuration builder yells at me.

Sure I can just use the optional override to set this behavior, but are there other things that will mysteriously just not work using the REST server?

And yes.... I'm still stuck.

Was it helpful?

Solution

I don't know how I missed this in my initial search, but I found the answer in another SO question.

infinispan cache server expiration failure

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top