title: Infinispan namedCache expiration
body: <p>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.</p>
  
  <pre><code>&lt;infinispan&gt;
      &lt;namedCache name="keydata"&gt;
          &lt;!-- http://infinispan.org/docs/5.2.x/user_guide/user_guide.html#_expiration_2 --&gt;
          &lt;expiration lifespan="1000" reaperEnabled="true" /&gt;
      &lt;/namedCache&gt;
  &lt;/infinispan&gt;
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>If I then hit the server with a GET, the cached value comes back.  Here is the trace when I do that.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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?</p>
  
  <p>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.</p>
  
  <p>Thanks!</p>
  
  <p>EDIT:</p>
  
  <p>I am digging through infinispan source code and see this in the org.infinispan.container.InternalEntryFactoryImpl:</p>
  
  <pre><code>@Override
  public InternalCacheEntry create(Object key, Object value, EntryVersion ignored, long lifespan, long maxIdle) {
      if (lifespan &lt; 0 &amp;&amp; maxIdle &lt; 0) return new ImmortalCacheEntry(key, value);
      if (lifespan &gt; -1 &amp;&amp; maxIdle &lt; 0) return new MortalCacheEntry(key, value, lifespan);
      if (lifespan &lt; 0 &amp;&amp; maxIdle &gt; -1) return new TransientCacheEntry(key, value, maxIdle);
  
      return new TransientMortalCacheEntry(key, value, maxIdle, lifespan);
  }
  </code></pre>
  
  <p>The VersionedInternalEntryFactoryImpl looks the same.  I know it's getting my lifespan value, so what gives?  Brain... hurts...</p>
  
  <p>EDIT 2 :</p>
  
  <p>I just noticed something interesting.  When I created the entry, I see this:</p>
  
  <pre><code>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}.
  </code></pre>
  
  <p>Looks like it isn't getting my lifespan value after all...</p>
  
  <p>EDIT 3:</p>
  
  <p>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.</p>
  
  <p><a href="http://infinispan.org/docs/5.2.x/user_guide/user_guide.html#_headers" rel="nofollow">http://infinispan.org/docs/5.2.x/user_guide/user_guide.html#_headers</a></p>
  
  <p>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.</p>
  
  <p>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?</p>
  
  <p>And yes.... I'm still stuck.</p>