Interface TokenCache

All Known Implementing Classes:
BoundedLruTokenCache

public interface TokenCache
SPI for caching the result of an OAuth introspection or token-acquisition call.

Two value shapes are supported via dedicated entry types: validator-side caches store CachedPrincipal (used by OAuthIntrospectionValidator); flow-side caches store OAuthToken. Implementations are not required to support both surfaces — a Redis-backed impl can serialize either via JSON, an in-memory impl can hold both. The default impl BoundedLruTokenCache supports both.

Implementations must be thread-safe.

Since:
10.0.0
  • Method Details

    • putPrincipal

      void putPrincipal(String key, Principal principal, Duration ttl)
      Stores or replaces a principal entry.
      Parameters:
      key - The cache key (typically the opaque token string). Never null.
      principal - The principal to cache. Never null.
      ttl - The maximum cache lifetime relative to "now". Must be positive.
    • getPrincipal

      Retrieves a non-expired principal entry.
      Parameters:
      key - The cache key.
      Returns:
      The cached principal, or Optional.empty() if absent or expired.
    • putToken

      void putToken(String key, OAuthToken token)
      Stores or replaces a token entry.
      Parameters:
      key - The cache key (typically a stable key derived from the flow parameters).
      token - The token to cache. Never null.
    • getToken

      Retrieves a non-expired token entry.
      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

      void invalidate(String key)
      Removes the entry under the supplied key. No-op if absent.
      Parameters:
      key - The cache key.
    • size

      int size()
      Returns the current entry count. Primarily for tests and metrics.
      Returns:
      The entry count.