1 Reply Latest reply on Apr 10, 2012 6:09 AM by Galder Zamarreño

    Manage eviction of long-loading data

    Michal Glowacki Novice

      hello,

       

         due to the suspiction, that my current solution is having a cache-memory leak I want to migrate some code to Infinispan. Now I use Seam 2.3 s:cache tags with JBoss Cache 1.0/2.0. I've read that there is a bug somewhere, that data might be not evicted. I suspect it, as my JBoss instance is growing for few days to almost 9GB (-Xmx 8GB) and then slows down/crashes - probably GC cannot free much more memory and works too often.

       

           So I want to get rid of s:cache tags and replace with EL expressions with Infinispan.

       

           The questions is, what would be the best strategy to evict old data, as generation of new data takes a long time. In better words, I am aware of situation:

       

      Data A has time to live 5 mins.

       

      After 5 mins it becomes obsolete, new one should be generated and put into cache.

       

      Hundreds of threads starts to generate new data and in the end race to put it into cache.

       

           I cache a data that takes some long time to be generated, like complex SQL queries that generate often 15-30 seconds. I've been looking for many websites for solution of this, however everywhere I found same pattern, get data from cache, if no valid, generate and put into cache again. I tried it in the past and I know that my busy application for sure will result with hundreds of threads blocked and datasource will run out of connections.

       

      Any advice would be appreciated,

      Michal

        • 1. Re: Manage eviction of long-loading data
          Galder Zamarreño Master

          With Infinispan, you can give a specific lifespan to data, so you can get it to last for 5 minutes.

           

          The typical code pattern is that you query the cache with a key, and if value not found, put the data for 5 minutes. Further requests will find the data and will not update the cache. Once the 5 minutes have expired, the cache query with the key will indicate no key is present and so you store again.

           

          You can also configure maxIdle time after which data is expired from memory.