Class ClientSessionMemoryCache

java.lang.Object
io.github.mahmoudimus.quic.tls.ClientSessionMemoryCache
All Implemented Interfaces:
ClientSessionStore

public final class ClientSessionMemoryCache extends Object implements ClientSessionStore
A bounded, in-memory ClientSessionStore: up to a number of servers, each with up to 8 tickets. A full cache forgets the server added first; a full server entry forgets its oldest ticket. Tickets are taken newest first, and only once.

Thread-safe: a ReentrantLock guards the map.

  • Field Details

    • MAX_TICKETS_PER_SERVER

      public static final int MAX_TICKETS_PER_SERVER
      The tickets kept per server, as rustls keeps.
      See Also:
    • DEFAULT_MAX_SERVERS

      public static final int DEFAULT_MAX_SERVERS
      The default number of servers.
      See Also:
  • Constructor Details

    • ClientSessionMemoryCache

      public ClientSessionMemoryCache()
      A cache for 256 servers.
    • ClientSessionMemoryCache

      public ClientSessionMemoryCache(int maxServers)
      A cache.
      Parameters:
      maxServers - the most servers to remember; 0 remembers none
  • Method Details

    • put

      public void put(String key, SessionTicket ticket)
      Description copied from interface: ClientSessionStore
      Keeps a ticket.
      Specified by:
      put in interface ClientSessionStore
      Parameters:
      key - the server it is for: its name, or another key the caller uses consistently
      ticket - the ticket
    • take

      public SessionTicket take(String key)
      Description copied from interface: ClientSessionStore
      Takes the newest ticket for a server, removing it.
      Specified by:
      take in interface ClientSessionStore
      Parameters:
      key - the server
      Returns:
      the ticket, or null if there is none
    • size

      public int size(String key)
      The number of tickets kept for a server.
      Parameters:
      key - the server
      Returns:
      the count