Class LongestExpireCacheStrategy

  • All Implemented Interfaces:
    ICacheStrategy

    public class LongestExpireCacheStrategy
    extends Object
    implements ICacheStrategy
    This class is to cache Jwts with "LongestExpire" strategy, which means: When the cache pool meets the capacity and a new jwt with provided key needs to be cached: the token with the longest expiry time will be the last to be replaced, the token with the least expiry time will be the first to be replace.
    • Constructor Detail

      • LongestExpireCacheStrategy

        public LongestExpireCacheStrategy​(int capacity)
    • Method Detail

      • cacheJwt

        public void cacheJwt​(Jwt.Key cachedKey,
                             Jwt jwt)
        This method is to cache a jwt LongestExpireCacheStrategy based on a given Jwt.Key and a Jwt. Every time it updates the expiry time of a jwt, and shift it up to a proper position. Since the PriorityQueue is implemented by heap, the average O(n) should be O(log n).
        Specified by:
        cacheJwt in interface ICacheStrategy
        Parameters:
        cachedKey - Jwt.Key the key to be used to cache
        jwt - Jwt the jwt to be cached
      • getCachedJwt

        public Jwt getCachedJwt​(Jwt.Key key)
        get Jwt from cache pool based on provided Jwt.Key key
        Specified by:
        getCachedJwt in interface ICacheStrategy
        Parameters:
        key - Jwt.Key
        Returns:
        Jwt jwt