com.hazelcast.map.eviction

## Class MapEvictionPolicy<K,V>

- java.lang.Object
- - com.hazelcast.map.eviction.MapEvictionPolicy<K,V>

- Type Parameters:
    `K` - the type of keys maintained by IMap
    `V` - the type of mapped values
  All Implemented Interfaces:
    Comparator<EntryView<K,V>>
  Direct Known Subclasses:
    LFUEvictionPolicy, LRUEvictionPolicy, RandomEvictionPolicy

      public abstract class MapEvictionPolicy<K,V>
      extends Object
      implements Comparator<EntryView<K,V>>

  An eviction policy takes its role after the decision that a map needs to free some memory according to one of `MaxSizePolicies` and it helps to find most appropriate entries to remove. `IMap` has out-of-the-box eviction policies like `LRUEvictionPolicy`, `LFUEvictionPolicy` and `RandomEvictionPolicy` but if there is a need to define another eviction policy, users can introduce a custom one by extending `MapEvictionPolicy` class.

  Implementation:

  `compare(EntryView, EntryView)` method must be implemented to provide an ascending order of entries. Because internal eviction algorithm will evict the smallest entry from `IMap`
  Since:
    3.7
  See Also:
    `LRUEvictionPolicy`, `LFUEvictionPolicy`, `RandomEvictionPolicy`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MapEvictionPolicy()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract int` | `compare(EntryView<K,V> entryView1, EntryView<K,V> entryView2)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface java.util.Comparator

      `comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong`

- - ### Constructor Detail

    - #### MapEvictionPolicy

          public MapEvictionPolicy()

  - ### Method Detail

    - #### compare

          public abstract int compare(EntryView<K,V> entryView1,
                                      EntryView<K,V> entryView2)

      If you prefer to evict the 1st entry then return negative number, if the 2nd entry is a better candidate then return a positive number or return 0 if both entries are equally good candidates for eviction

      Specified by:
        `compare` in interface `Comparator<EntryView<K,V>>`

Copyright © 2020. All rights reserved.