Package io.github.mahmoudimus.quic.token
Class TokenMemoryCache
java.lang.Object
io.github.mahmoudimus.quic.token.TokenMemoryCache
- All Implemented Interfaces:
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.
-
Field Summary
Fields inherited from interface io.github.mahmoudimus.quic.token.TokenStore
NONE -
Constructor Summary
ConstructorsConstructorDescriptionA cache with quinn's defaults: 256 server names, 2 tokens each.TokenMemoryCache(int maxServerNames, int maxTokensPerServer) A cache. -
Method Summary
-
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 nothingmaxTokensPerServer- the most tokens per server name; 0 keeps nothing
-
-
Method Details
-
put
Description copied from interface:TokenStoreKeeps a token for later, one-time use.- Specified by:
putin interfaceTokenStore- Parameters:
serverName- the server it came fromtoken- the token
-
take
Description copied from interface:TokenStoreTakes a token for a server, removing it.- Specified by:
takein interfaceTokenStore- Parameters:
serverName- the server- Returns:
- the token, or null if there is none
-