3 Replies Latest reply on Feb 2, 2012 3:34 AM by Galder Zamarreño

    Can I customize my own eviction strategy?

    Forever Pi Newbie

      Hi,

          

      I have a requirement that need to use an eviction strategy which is different from LIRS or LRU. For example, I need to evict cache entries according to their memory size, the smallest entry should be evicted from the memory first.

       

      I have read a bit of infinispan source, and I didn't seem to find an interface that provides eviction strategy customization. If do have one, how can I configure it? If eviction can't be customized, are there other ways to achieve my purpose?

       

      Thanks a lot.

        • 1. Re: Can I customize my own eviction strategy?
          Galder Zamarreño Master

          First of all, the eviction strategy is not currently pluggable.

           

          Also, why do you need such eviction strategy? What is it that you're trying to achieve with it?

           

          Eviction strategies are all about evicting stuff that's not in use and has not been used recently. LIRS is perfect for that. If you use other strategies, you might end up with unnecessary misses.

           

          You might be evicting the smallest thing but if the smallest thing is the thing that's used the most, you're getting nothing out of caching.

          1 of 1 people found this helpful
          • 2. Re: Can I customize my own eviction strategy?
            Forever Pi Newbie

            You are right. Simply evicting the smallest thing from the memory is meaningless.

             

            But it might make sense if I just want those big entries not to be evicted from the memory before there are some ones smaller than them, because the price to reload them back into memory is high. And I didn't find a EntryChosenForEvictionListner to be used for my purpose. That's what I am confused.

            • 3. Re: Can I customize my own eviction strategy?
              Galder Zamarreño Master

              Right, I see what you mean now. So, the extension you're looking for is not available, nor Infinispan can provide information about the size of the object.

               

              However, something you can do is have a cache listener and listen for @CacheEntriesEvicted, so when entries are evicted, you can get a map of key/value pairs that are evicted. You could then judge the size of the value and prefetch it in advance to avoid paying the price of reloading them when they're needed. That's assuming of course that the cost variable is time. If the cost variable is money, i.e. retrieving it from Amazon S3, then a I'd suggest tweaking the put() calls accordingly to pass a bigger lifespan and/or maxIdle time for bigger values so that they stay in memory for longer.