1 of 1 people found this helpful
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.
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.
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.