/** * Adds the given session to the cache. */ final void cacheSession(NativeSslSession session) { byte[] id = session.getId(); if (id == null || id.length == 0) { return; } synchronized (sessions) { ByteArray key = new ByteArray(id); if (sessions.containsKey(key)) { removeSession(sessions.get(key)); } // Let the subclass know. onBeforeAddSession(session); sessions.put(key, session); } }
/** * Adds the given session to the cache. */ final void cacheSession(NativeSslSession session) { byte[] id = session.getId(); if (id == null || id.length == 0) { return; } synchronized (sessions) { ByteArray key = new ByteArray(id); if (sessions.containsKey(key)) { removeSession(sessions.get(key)); } // Let the subclass know. onBeforeAddSession(session); sessions.put(key, session); } }
/** * Called for server sessions only. Retrieves the session by its ID. Overridden by * {@link ServerSessionContext} to */ final NativeSslSession getSessionFromCache(byte[] sessionId) { if (sessionId == null) { return null; } // First, look in the in-memory cache. NativeSslSession session; synchronized (sessions) { session = sessions.get(new ByteArray(sessionId)); } if (session != null && session.isValid()) { if (session.isSingleUse()) { removeSession(session); } return session; } // Look in persistent cache. We don't currently delete sessions from the persistent // cache, so we may find a multi-use (aka TLS 1.2) session after having received and // then used up one or more single-use (aka TLS 1.3) sessions. return getSessionFromPersistentCache(sessionId); }
/** * Called for server sessions only. Retrieves the session by its ID. Overridden by * {@link ServerSessionContext} to */ final NativeSslSession getSessionFromCache(byte[] sessionId) { if (sessionId == null) { return null; } // First, look in the in-memory cache. NativeSslSession session; synchronized (sessions) { session = sessions.get(new ByteArray(sessionId)); } if (session != null && session.isValid()) { if (session.isSingleUse()) { removeSession(session); } return session; } // Look in persistent cache. We don't currently delete sessions from the persistent // cache, so we may find a multi-use (aka TLS 1.2) session after having received and // then used up one or more single-use (aka TLS 1.3) sessions. return getSessionFromPersistentCache(sessionId); }