private void trimToSize() {
        synchronized (sessions) {
            int size = sessions.size();
            if (size > maximumSize) {
                int removals = size - maximumSize;
                Iterator<NativeSslSession> i = sessions.values().iterator();
                while (removals-- > 0) {
                    NativeSslSession session = i.next();
                    onBeforeRemoveSession(session);
                    i.remove();
                }
            }
        }
    }
Makes sure cache size is < maximumSize.
common/src/main/java/org/conscrypt/AbstractSessionContext.java