Class LongestExpireCacheStrategy
- java.lang.Object
-
- com.networknt.http.client.oauth.cache.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 Summary
Constructors Constructor Description LongestExpireCacheStrategy(int capacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcacheJwt(Jwt.Key cachedKey, Jwt jwt)This method is to cache a jwt LongestExpireCacheStrategy based on a given Jwt.Key and a Jwt.JwtgetCachedJwt(Jwt.Key key)get Jwt from cache pool based on provided Jwt.Key key
-
-
-
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:
cacheJwtin interfaceICacheStrategy- Parameters:
cachedKey- Jwt.Key the key to be used to cachejwt- 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:
getCachedJwtin interfaceICacheStrategy- Parameters:
key- Jwt.Key- Returns:
- Jwt jwt
-
-