5 Replies Latest reply on Oct 21, 2010 8:12 AM by trustin

    Being notified by EvictionManager

    eboily

      Hi,

       

      Is there any way to get notified when the EvictionManager purges expired entries or prunes the cache?

       

      I need to be notified when any entry is removed from the cache. I looked at interceptors and notifications and none seems to support what I want.

       

      I'm using 4.1.0-FINAL.

       

      Any idea?

       

      Thanks,

       

      - Edouard

        • 1. Re: Being notified by EvictionManager
          vblagojevic

          So you want to be notified when expired entry is pruned/evicted from cache? We do not have that listener/event. We can either add a flag expired to CacheEntryEvictedEvent or add a new event say CacheEntryExpiredEvent which would mean that the entry has expired and has been evicted from cache.

           

          Which one makes more sense to you? Anyone else?

           

          Regards,

          Vladimir

          1 of 1 people found this helpful
          • 2. Re: Being notified by EvictionManager
            eboily
            My requirement is that I must know whenever an entry is removed from the cache.
            I see multiple situations where an entry is removed from the cache:
            1. an entry is explicitly evicted using cache.evict(key).
            2. a non expired entry is pruned when adding a new entry and maxEntries is reached.
            3. a non expired entry is pruned by the EvictionManager thread (in coming PIGGYBACK mode)
            4. an expired (over maxIdle) entry is removed by the EvictionManager thread
            5. an expired (over lifespan) entry is removed by the EvictionManager thread
            Cases 1 and 2 are already supported by a notification. No issues here.
            However, cases 3, 4 and 5 are not currently supported by notifications.
            The notification can be either en evicted notification with a "reason" flag or a new expired notification. I think the "reason" flag would be more generic encompass the five types of eviction mentioned above.

            Hi again Vladimir,

             

            My requirement is that I must know whenever an entry is removed from the cache.

             

            I see multiple situations where an entry is removed from the cache:

            1. an entry is explicitly evicted using cache.evict(key).
            2. a non expired entry is pruned when adding a new entry and maxEntries is reached.
            3. a non expired entry is pruned by the EvictionManager thread (in coming PIGGYBACK mode)
            4. an expired (over maxIdle) entry is removed by the EvictionManager thread
            5. an expired (over lifespan) entry is removed by the EvictionManager thread

             

            Cases 1 and 2 are already supported by the CacheEntryEvicted notification. No issues here.

             

            However, cases 3, 4 and 5 are not currently supported by any notification (as far as I've looked in the code and experimented).

             

            The notification can either be a CacheEntryEvicted notification with a "reason" flag or a new CacheEntryExpired notification. But I think the CacheEntryEvicted notification with a "reason" flag would be far more generic because it could encompass the five types of eviction mentioned above. This way you would have the "reason" flag settable to EXPLICIT, PRUNED and EXPIRED.

             

            There is a business reason why one may want to differentiate pruned evictions from expired eviction: a pruned eviction implies the cache is full, which may trigger a different reaction than an expired eviction. These notifications and this distinction also greatly facilitates QA tasks.

             

            My two cents.

             

             

            Anybody else?

             

            - Edouard

            • 3. Re: Being notified by EvictionManager
              vblagojevic

              In order to conform to an existing framework most likely we will have to implement a separate event - CacheEntryExpired. Also we probably can not differentiate if it was an explicit, pruned etc etc. Please create a JIRA task and we'll put it into task pipeline.

               

              Best regards,

              Vladimir

              1 of 1 people found this helpful
              • 4. Re: Being notified by EvictionManager
                eboily

                Hi Vladimir,

                 

                If you want to go with an Expired event, I may have a quick patch that I did yesterday that implement this.

                Please see the patch file attached to this message.

                 

                Basically, I overloaded

                void purgeExpired();
                /**
                * Purges entries that have passed their expiry time and notify eviction listeners.
                */
                void purgeExpired(CacheNotifier cacheNotifier);

                 

                DataContainer.purgeExpired();

                 

                with

                 

                DataContainer.purgeExpired(CacheNotifier cacheNotifier);


                and I call it from EvictionManagerImpl.processEviction(), replacing dataContainer.purgeExpired() by dataContainer.purgeExpired(cacheNotifier). I also created the proper event. However, I do not use exactly the same signature as for the other notifiers. I use
                void notifyCacheEntryExpired(Object key);

                instead of a signature similar to
                void notifyCacheEntryEvicted(Object key, boolean pre, InvocationContext ctx);

                It has been done quickly but it works.
                You can apply the patch file with a level 1 strip (-p1) as follows
                # cd infinispan-4.1.0.FINAL
                # patch -p1 <../ExpiredEvent.patch

                I hope this helps.
                Best redgards,
                - Edouard
                • 5. Re: Being notified by EvictionManager
                  trustin

                  I left a comment to the JIRA issue - ISPN-694.