Class TokenMemoryCache

java.lang.Object
io.github.mahmoudimus.quic.token.TokenMemoryCache
All Implemented Interfaces:
TokenStore

public final class TokenMemoryCache extends Object implements TokenStore
A bounded, in-memory TokenStore: up to a number of server names, each with a queue of up to a number of tokens. Storing a token for a full queue drops its oldest; storing one for a new name when the cache is full evicts the least recently used name. Tokens are taken oldest first.

Thread-safe: a ReentrantLock guards the map.

  • Constructor Details

    • TokenMemoryCache

      public TokenMemoryCache()
      A cache with quinn's defaults: 256 server names, 2 tokens each.
    • TokenMemoryCache

      public TokenMemoryCache(int maxServerNames, int maxTokensPerServer)
      A cache.
      Parameters:
      maxServerNames - the most server names to remember; 0 keeps nothing
      maxTokensPerServer - the most tokens per server name; 0 keeps nothing
  • Method Details

    • put

      public void put(String serverName, byte[] token)
      Description copied from interface: TokenStore
      Keeps a token for later, one-time use.
      Specified by:
      put in interface TokenStore
      Parameters:
      serverName - the server it came from
      token - the token
    • take

      public byte[] take(String serverName)
      Description copied from interface: TokenStore
      Takes a token for a server, removing it.
      Specified by:
      take in interface TokenStore
      Parameters:
      serverName - the server
      Returns:
      the token, or null if there is none