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 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 (see putSessionData(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 Details

    • directory

      final File directory
      Directory to store session files in.
    • accessOrder

      Map<String,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

      String[] initialFiles
      The initial set of files. We use this to defer adding information about all files to accessOrder until necessary.
  • Constructor Details

  • Method Details

    • newAccessOrder

      private static Map<String,File> newAccessOrder()
      Creates a new access-ordered linked hash map.
    • fileName

      private static String fileName(String host, int port)
      Gets the file name for the given host and port.
    • getSessionData

      public byte[] getSessionData(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 interface SSLClientSessionCache
      Parameters:
      host - from SSLSession.getPeerHost()
      port - from SSLSession.getPeerPort()
      Returns:
      the session data or null if none is cached
    • logReadError

      static void logReadError(String host, File file, Throwable t)
    • putSessionData

      public void putSessionData(SSLSession session, byte[] sessionData)
      Description copied from interface: SSLClientSessionCache
      Stores session data for the given session.
      Specified by:
      putSessionData in interface SSLClientSessionCache
      Parameters:
      session - to cache data for
      sessionData - 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(File file)
    • logWriteError

      static void logWriteError(String host, File file, Throwable t)