private void evict()

in phoenix-queryserver/src/main/java/org/apache/phoenix/util/SimpleLRUCache.java [66:94]


    private void evict() {
        synchronized(this) {
            int currentSize = this.size();
            if (currentSize <= triggerSize) {
                return;
            }
            LOG.warn("UGI Cache capacity exceeded, you may want to increase its size");
            TreeSet<Entry<K, AtomicLong>> sortedByLRU = new TreeSet<>(
                    new Comparator<Entry<K, AtomicLong>>() {
                        @Override
                        public int compare(Entry<K, AtomicLong> o1, Entry<K, AtomicLong> o2) {
                            int keyResult =
                                    Long.compare(o2.getValue().get(), o1.getValue().get());
                            if(keyResult == 0) {
                                return o2.getKey().compareTo(o1.getKey());
                            } else {
                                return keyResult;
                            }
                        }
                    });
            sortedByLRU.addAll(accessed.entrySet());
            Entry<Object, AtomicLong>[] toRetain =
                    Arrays.copyOfRange(sortedByLRU.toArray(new Entry[currentSize]), 0, maxSize);
            java.util.List<Object> retainList =
                    Arrays.stream(toRetain).map( f -> f.getKey()).collect(Collectors.toList());
            this.keySet().retainAll(retainList);
            accessed.keySet().retainAll(this.keySet());
        }
    }