Package org.conscrypt
Class FileClientSessionCache.Impl
- java.lang.Object
-
- org.conscrypt.FileClientSessionCache.Impl
-
- All Implemented Interfaces:
SSLClientSessionCache
- Enclosing class:
- FileClientSessionCache
static class FileClientSessionCache.Impl extends java.lang.Object implements SSLClientSessionCache
This cache creates one file per SSL session using "host.port" for the file name. Files are created or replaced when session data is put in the cache (seeputSessionData(javax.net.ssl.SSLSession, byte[])
). Files are read on cache hits, but not on cache misses.When the number of session files exceeds MAX_SIZE, we delete the least-recently-used file. We don't current persist the last access time, so the ordering actually ends up being least-recently-modified in some cases and even just "not accessed in this process" if the filesystem doesn't track last modified times.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.Map<java.lang.String,java.io.File>
accessOrder
Map of name -> File.(package private) java.io.File
directory
Directory to store session files in.(package private) java.lang.String[]
initialFiles
The initial set of files.(package private) int
size
The number of files on disk.
-
Constructor Summary
Constructors Constructor Description Impl(java.io.File directory)
Constructs a new cache backed by the given directory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
delete(java.io.File file)
private static java.lang.String
fileName(java.lang.String host, int port)
Gets the file name for the given host and port.byte[]
getSessionData(java.lang.String host, int port)
Gets data from a pre-existing session for a given server host and port.private void
indexFiles()
Lazily updates accessOrder to know about all files as opposed to just the files accessed since this process started.(package private) static void
logReadError(java.lang.String host, java.io.File file, java.lang.Throwable t)
(package private) static void
logWriteError(java.lang.String host, java.io.File file, java.lang.Throwable t)
private void
makeRoom()
Deletes old files if necessary.private static java.util.Map<java.lang.String,java.io.File>
newAccessOrder()
Creates a new access-ordered linked hash map.void
putSessionData(javax.net.ssl.SSLSession session, byte[] sessionData)
Stores session data for the given session.
-
-
-
Field Detail
-
directory
final java.io.File directory
Directory to store session files in.
-
accessOrder
java.util.Map<java.lang.String,java.io.File> accessOrder
Map of name -> File. Keeps track of the order files were accessed in.
-
size
int size
The number of files on disk.
-
initialFiles
java.lang.String[] initialFiles
The initial set of files. We use this to defer adding information about all files to accessOrder until necessary.
-
-
Method Detail
-
newAccessOrder
private static java.util.Map<java.lang.String,java.io.File> newAccessOrder()
Creates a new access-ordered linked hash map.
-
fileName
private static java.lang.String fileName(java.lang.String host, int port)
Gets the file name for the given host and port.
-
getSessionData
public byte[] getSessionData(java.lang.String host, int port)
Description copied from interface:SSLClientSessionCache
Gets data from a pre-existing session for a given server host and port.- Specified by:
getSessionData
in interfaceSSLClientSessionCache
- Parameters:
host
- fromSSLSession.getPeerHost()
port
- fromSSLSession.getPeerPort()
- Returns:
- the session data or null if none is cached
-
logReadError
static void logReadError(java.lang.String host, java.io.File file, java.lang.Throwable t)
-
putSessionData
public void putSessionData(javax.net.ssl.SSLSession session, byte[] sessionData)
Description copied from interface:SSLClientSessionCache
Stores session data for the given session.- Specified by:
putSessionData
in interfaceSSLClientSessionCache
- Parameters:
session
- to cache data forsessionData
- to cache
-
makeRoom
private void makeRoom()
Deletes old files if necessary.
-
indexFiles
private void indexFiles()
Lazily updates accessOrder to know about all files as opposed to just the files accessed since this process started.
-
delete
private void delete(java.io.File file)
-
logWriteError
static void logWriteError(java.lang.String host, java.io.File file, java.lang.Throwable t)
-
-