private void putSession(HostAndPort key, NativeSslSession session) {
        synchronized (sessionsByHostAndPort) {
            List<NativeSslSession> sessions = sessionsByHostAndPort.get(key);
            if (sessions == null) {
                sessions = new ArrayList<NativeSslSession>();
                sessionsByHostAndPort.put(key, sessions);
            }
            // To maintain the invariant that single- and multi-use sessions aren't
            // mixed, check what the current list contains and remove those sessions if
            // they're of the other type.
            if (sessions.size() > 0 && sessions.get(0).isSingleUse() != session.isSingleUse()) {
                while (!sessions.isEmpty()) {
                    removeSession(sessions.get(0));
                }
                // The last removeSession() call will have removed the list from
                // the map, so put it back.
                sessionsByHostAndPort.put(key, sessions);
            }
            sessions.add(session);
        }
    }
Finds a cached session for the given host name and port.

@param host of server
@param port of server
@return cached session or null if none found
common/src/main/java/org/conscrypt/ClientSessionContext.java