Hi! Eviction policy specifies, which entries should be kept in on-heap memory in deserialized format. So, the access time will be the lowest for such entries, when read from the local node. But such entries are stored twice: once in off-heap and once in on-heap. And evicted entries are stored in off-heap memory anyway, so you are able to access such values, even when they are evicted from on-heap space.
Entries from off-heap memory can be evicted per page, based on last access time. It can be configured using the following method: *DataRegionConfiguration.setPageEvictionMode(...)* You can find all this information and more in the documentation: https://apacheignite.readme.io/docs/evictions P.S. Instances of Integer shouldn't be checked for equality, using == operator. They should be either unboxed first, or checked using equals() *CustomizedComparator.compare(...) *can be rewritten as follows: return Integer.compare(b.getValue(), a.getValue()); Denis вт, 27 февр. 2018 г. в 6:39, mamaco <mam...@163.com>: > Here I have a five entries as below: > (14,4); > (21,1); > (32,2); > (113,3); > (15,5); > and I want to use SortedEvictionPolicy to keep below 3 entries (sort by > values in descending order and get top 3 items): > 15-->5 > 14-->4 > 113-->3 > > The actual output is: > 21-->1 > 32-->2 > 113-->3 > 14-->4 > 15-->5 > > issue 1: The order is wrong, the class CustomizedComparator doesn't seem to > work. > issue 2: there are only 3 entries are expected, but it returns 5 ones, > MaxSize doesn't work. > Did I miss anything? > > The source code: > > package IgniteTesting.Expiry; > import javax.cache.Cache.Entry; > import org.apache.ignite.Ignite; > import org.apache.ignite.IgniteCache; > import org.apache.ignite.Ignition; > import org.apache.ignite.cache.CacheMode; > import org.apache.ignite.cache.eviction.sorted.SortedEvictionPolicy; > import org.apache.ignite.cache.query.QueryCursor; > import org.apache.ignite.cache.query.SqlQuery; > import org.apache.ignite.configuration.CacheConfiguration; > > public class Application > { > public static void main( String[] args ) > { > try(Ignite ignite = Ignition.start("......\\test.xml")){ > CacheConfiguration<Integer, Integer> cfg = new > CacheConfiguration<>(); > cfg.setName("foo"); > cfg.setOnheapCacheEnabled(true); > cfg.setCacheMode(CacheMode.LOCAL); > SortedEvictionPolicy<Integer,Integer> SEP = new > SortedEvictionPolicy<>(3,new CustomizedComparator()); > cfg.setEvictionPolicy(SEP); > cfg.setIndexedTypes(Integer.class, Integer.class); > > try(IgniteCache<Integer, Integer> > cache=ignite.getOrCreateCache(cfg)){ > cache.put(14,4); > cache.put(21,1); > cache.put(32,2); > cache.put(113,3); > cache.put(15,5); > > SqlQuery<Integer,Integer> sql = new > SqlQuery<>(Integer.class, "select > * from Integer"); > try (QueryCursor<Entry<Integer, Integer>> > cursor = > cache.query(sql)) { > for (Entry<Integer, Integer> e : cursor) > > System.out.println(e.getKey()+"-->"+e.getValue().toString()); > } > > > } > } > > } > } > > > package IgniteTesting.Expiry; > > import java.io.Serializable; > import java.util.Comparator; > import org.apache.ignite.cache.eviction.EvictableEntry; > > public class CustomizedComparator implements > Serializable,Comparator<EvictableEntry<Integer,Integer>> { > private static final long serialVersionUID = 4755938152431669886L; > > public int compare(EvictableEntry<Integer,Integer> a, > EvictableEntry<Integer,Integer> b) { > return a.getValue() > b.getValue() ? -1 : a.getValue() == > b.getValue() ? 0 : 1; > } > } > > > > > > -- > Sent from: http://apache-ignite-users.70518.x6.nabble.com/ >