Class PersistentTokenCache<T>

java.lang.Object
tech.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 a LinkedHashMap to keep the tokens in order of expiration. During access any entries which have expired are automatically purged.
  • 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

      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, unless purge() 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.