Class RefreshAheadCachingJWKSetSource<C extends SecurityContext>

All Implemented Interfaces:
JWKSetSource<C>, Closeable, AutoCloseable

@ThreadSafe public class RefreshAheadCachingJWKSetSource<C extends SecurityContext> extends CachingJWKSetSource<C>
Caching JWKSetSource that refreshes the JWK set prior to its expiration. The updates run on a separate, dedicated thread. Updates can be repeatedly scheduled, or (lazily) triggered by incoming requests for the JWK set.

This class is intended for uninterrupted operation under high-load, to avoid a potentially large number of threads blocking when the cache expires (and must be refreshed).

Version:
2025-06-24
Author:
Thomas Rørvik Skjølberg, Vladimir Dzhuvinov
  • Constructor Details

    • RefreshAheadCachingJWKSetSource

      public RefreshAheadCachingJWKSetSource(JWKSetSource<C> source, long timeToLive, long cacheRefreshTimeout, long refreshAheadTime, boolean scheduled, EventListener<CachingJWKSetSource<C>,C> eventListener)
      Creates a new refresh-ahead caching JWK set source.
      Parameters:
      source - The JWK set source to decorate. Must not be null.
      timeToLive - The time to live of the cached JWK set, in milliseconds.
      cacheRefreshTimeout - The cache refresh timeout, in milliseconds.
      refreshAheadTime - The refresh ahead time, in milliseconds.
      scheduled - true to refresh in a scheduled manner, regardless of requests.
      eventListener - The event listener, null if not specified.
    • RefreshAheadCachingJWKSetSource

      public RefreshAheadCachingJWKSetSource(JWKSetSource<C> source, long timeToLive, long cacheRefreshTimeout, long refreshAheadTime, boolean scheduled, ExecutorService executorService, boolean shutdownExecutorOnClose, EventListener<CachingJWKSetSource<C>,C> eventListener)
      Creates a new refresh-ahead caching JWK set source with the specified executor service to run the updates in the background.
      Parameters:
      source - The JWK set source to decorate. Must not be null.
      timeToLive - The time to live of the cached JWK set, in milliseconds.
      cacheRefreshTimeout - The cache refresh timeout, in milliseconds.
      refreshAheadTime - The refresh ahead time, in milliseconds.
      scheduled - true to refresh in a scheduled manner, regardless of requests.
      executorService - The executor service to run the updates in the background.
      shutdownExecutorOnClose - If true the executor service will be shut down upon closing the source.
      eventListener - The event listener, null if not specified.
    • RefreshAheadCachingJWKSetSource

      public RefreshAheadCachingJWKSetSource(JWKSetSource<C> source, long timeToLive, long cacheRefreshTimeout, long refreshAheadTime, ExecutorService executorService, boolean shutdownExecutorOnClose, EventListener<CachingJWKSetSource<C>,C> eventListener, ScheduledExecutorService scheduledExecutorService, boolean shutdownScheduledExecutorOnClose)
      Creates a new refresh-ahead caching JWK set source with the specified ExecutorService to run the updates in the background. The parameters include an optional ScheduledExecutorService to schedule the updates in the background.

      Note about the ScheduledExecutorService: It is assumed that a thread will be available to schedule the update of the cache when needed. If this is not the case then the updates will not be scheduled on-time. This could, in the worst-case scenario, lead to the cache being expired when getJWKSet(JWKSetCacheRefreshEvaluator, long, SecurityContext) is called.

      Parameters:
      source - The JWK set source to decorate. Must not be null.
      timeToLive - The time to live of the cached JWK set, in milliseconds.
      cacheRefreshTimeout - The cache refresh timeout, in milliseconds.
      refreshAheadTime - The refresh ahead time, in milliseconds.
      executorService - The executor service to run the updates in the background.
      shutdownExecutorOnClose - If true the executor service will be shut down upon closing the source.
      eventListener - The event listener, null if not specified.
      scheduledExecutorService - The ScheduledExecutorService to schedule the updates in the background. If null no updates will be scheduled.
      shutdownScheduledExecutorOnClose - If true then the ScheduledExecutorService will be shut down upon closing the source.
  • Method Details