5 Replies Latest reply on Jul 14, 2012 4:02 AM by galder.zamarreno

    Handling expiration events in the app

    vdzhuvinov

      Hi guys!

       

      We have a web app with a primary cache and a number of auxiliary caches with entries depending on the primary ones. When an entry in the primary cache expires this should trigger various cascading operations in the dependant caches with the key of the expiring primary entry as an argument.

       

      If my understanding is correct, Infinispan doesn't support expiration listeners (ISPN-694). What is then the recommended approach to allow an application to act on entry expiration?

       

      The solution that comes to my mind is to write our own in-app expiration code, based on Cache.entrySet() and removeAsync(). Is this the most efficient approach? I read that entrySet() is not a cheap operation with replicated/distributed caches.

       

      Your advice will be greatly appreciated.

       

      Cheers,

       

      Vladimir

        • 1. Re: Handling expiration events in the app
          galder.zamarreno

          Have you tried if CacheEntryRemovedEvent works for your use case?

          1 of 1 people found this helpful
          • 2. Re: Handling expiration events in the app
            vdzhuvinov

            Hi Galder,

             

            CacheEntryRemovedEvent is meant for explicit removal only, not for removal due to expiration.

             

            What we ultimately did was to create our own expiration logic and then use Infinispan's cache entry removed event to distribute the message to local and remote nodes.

             

            I still find it a bit odd that expire events are not supported, given the fact that remove events are.

            • 3. Re: Handling expiration events in the app
              galder.zamarreno

              Ah yes, I forgot. The jira issue that you linked explains some of the caveats of implementing this, particularly when the expired elements are not in memory but in the cache store.

               

              The other slight problem is that a lot of the logic to check for expired elements is within the inner data container, where we can remove entries directly without emitting any notifications.

               

              Btw, out of curiosity, what kind of things do you do when the entry is expired?

              • 4. Re: Handling expiration events in the app
                vdzhuvinov

                The system in question acts as an enterprise JSON web service for Single Sign-On (SSO), shared session management and OpenID Connect IdP/IdC.

                 

                Expiration events are primarily used with sessions:

                 

                • Send web events to listenening apps that a user's session has expired.
                • Release shared session data objects.
                • Release optional LDAP connection bound as the user during the session.
                • Register event with the session logger.
                • Update various user stats.

                 

                We spent about three months evaluating Ehcache/Terracotta and Infinispan, and in the end decided to settle for the latter, despite the lack of Infinispan expiration events. These we reproduced by creating our own expiration logic on top of Infinispan.

                 

                The whole experience is worth writing a book

                • 5. Re: Handling expiration events in the app
                  galder.zamarreno

                  I dunno the JBoss Application Server code by hard, but this is the kind of stuff the clustering integration code needs to deal with, so I'd suggest you dig a little into https://github.com/jbossas/jboss-as/tree/master/clustering to see what's done when web  sessions expire and how they deal with capturing these events. I suspect that, as if you're already doing, they might have an external service, within the web container, that tells them when a session has expired, and so end up with a similar solution to yours.

                   

                  I'd love to read that book