Package tech.jhipster.security
Class PersistentTokenCache<T>
java.lang.Object
tech.jhipster.security.PersistentTokenCache<T>
Simple time-limited cache for login tokens, necessary to avoid concurrent
requests invalidating one another. It uses a
LinkedHashMap
to keep the tokens in order of expiration. During access any entries which
have expired are automatically purged.-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
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 Details
-
get
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
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.
-