Class BoundedLruTokenCache
java.lang.Object
org.apache.juneau.rest.server.auth.oauth.BoundedLruTokenCache
- All Implemented Interfaces:
TokenCache
Thread-safe bounded LRU implementation of
TokenCache.
Backed by a LinkedHashMap configured with accessOrder=true so iteration order tracks
most-recently-used. Eviction policy is the conjunction of:
- Size cap — when the entry count would exceed
maxEntries, the least-recently-used entry is removed before the new entry is inserted. DefaultmaxEntries=1000. - TTL eviction — on lookup, an entry whose stored expiry instant has passed (relative to
the supplied
nowclock) is removed and treated as a miss.
- Since:
- 10.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault maximum entry count. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BoundedLruTokenCachecreate()Static creator with the default max-entries.static BoundedLruTokenCachecreate(int maxEntries) Static creator with a custom max-entries.intReturns the configured maximum entry count.getPrincipal(String key) Retrieves a non-expired principal entry.Retrieves a non-expired token entry.voidinvalidate(String key) Removes the entry under the supplied key.voidputPrincipal(String key, Principal principal, Duration ttl) Stores or replaces a principal entry.voidputToken(String key, OAuthToken token) Stores or replaces a token entry.intsize()Returns the current entry count.
-
Field Details
-
DEFAULT_MAX_ENTRIES
Default maximum entry count.- See Also:
-
-
Constructor Details
-
BoundedLruTokenCache
Constructor.- Parameters:
maxEntries- The maximum entry count.
-
-
Method Details
-
create
Static creator with the default max-entries.- Returns:
- A new cache.
-
create
Static creator with a custom max-entries.- Parameters:
maxEntries- The maximum entry count. Must be positive.- Returns:
- A new cache.
-
getMaxEntries
Returns the configured maximum entry count.- Returns:
- The maximum entry count.
-
putPrincipal
Description copied from interface:TokenCacheStores or replaces a principal entry.- Specified by:
putPrincipalin interfaceTokenCache- Parameters:
key- The cache key (typically the opaque token string). Nevernull.principal- The principal to cache. Nevernull.ttl- The maximum cache lifetime relative to "now". Must be positive.
-
getPrincipal
Description copied from interface:TokenCacheRetrieves a non-expired principal entry.- Specified by:
getPrincipalin interfaceTokenCache- Parameters:
key- The cache key.- Returns:
- The cached principal, or
Optional.empty()if absent or expired.
-
putToken
Description copied from interface:TokenCacheStores or replaces a token entry.- Specified by:
putTokenin interfaceTokenCache- Parameters:
key- The cache key (typically a stable key derived from the flow parameters).token- The token to cache. Nevernull.
-
getToken
Description copied from interface:TokenCacheRetrieves a non-expired token entry.- Specified by:
getTokenin interfaceTokenCache- Parameters:
key- The cache key.now- The reference instant for expiry comparison.skew- Skew tolerance subtracted from the entry's expiry. Must be non-negative.- Returns:
- The cached token, or
Optional.empty()if absent or expired.
-
invalidate
Description copied from interface:TokenCacheRemoves the entry under the supplied key. No-op if absent.- Specified by:
invalidatein interfaceTokenCache- Parameters:
key- The cache key.
-
size
Description copied from interface:TokenCacheReturns the current entry count. Primarily for tests and metrics.- Specified by:
sizein interfaceTokenCache- Returns:
- The entry count.
-