Package io.github.jhipster.security
Class PersistentTokenCache<T>
- java.lang.Object
-
- io.github.jhipster.security.PersistentTokenCache<T>
-
public class PersistentTokenCache<T> extends Object
Simple time-limited cache for login tokens, necessary to avoid concurrent requests invalidating one another. It uses aLinkedHashMapto keep the tokens in order of expiration. During access any entries which have expired are automatically purged.
-
-
Constructor Summary
Constructors Constructor Description PersistentTokenCache(long expireMillis)Construct a new TokenCache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tget(String key)Get a token from the cache.voidpurge()Remove expired entries from the map.voidput(String key, T token)Put a token in the cache.intsize()Get the number of tokens in the cache.
-
-
-
Constructor Detail
-
PersistentTokenCache
public PersistentTokenCache(long expireMillis)
Construct a new TokenCache.- Parameters:
expireMillis- Delay until tokens expire, in millis.- Throws:
IllegalArgumentException- if expireMillis is non-positive.
-
-
Method Detail
-
get
public T get(String key)
Get a token from the cache.- Parameters:
key- The key to look for.- Returns:
- The token, if present and not yet expired, or null otherwise.
-
put
public void put(String key, T token)
Put a token in the cache. If a token already exists for the given key, it is replaced.- Parameters:
key- The key to insert for.token- The token to insert.
-
size
public int size()
Get the number of tokens in the cache. Note, this may include expired tokens, unlesspurge()is invoked first.- Returns:
- The size of the cache.
-
purge
public void purge()
Remove expired entries from the map. This will be called automatically before read/write access, but could be manually invoked if desired.
-
-