Class ERCache<V>

java.lang.Object
io.apicurio.registry.resolver.cache.ERCache<V>

public class ERCache<V> extends Object
Expiration and Retry Cache
  • Constructor Details

    • ERCache

      public ERCache()
  • Method Details

    • configureLifetime

      public void configureLifetime(Duration lifetime)
    • configureRetryBackoff

      public void configureRetryBackoff(Duration backoff)
    • configureRetryCount

      public void configureRetryCount(long retries)
    • configureCacheLatest

      public void configureCacheLatest(boolean cacheLatest)
      If true, will cache schema lookups that either have `latest` or no version specified. Setting this to false will effectively disable caching for schema lookups that do not specify a version.
      Parameters:
      cacheLatest - Whether to enable cache of artifacts without a version specified.
    • configureFaultTolerantRefresh

      public void configureFaultTolerantRefresh(boolean faultTolerantRefresh)
      If set to true, will log the load error instead of throwing it when an exception occurs trying to refresh a cache entry. This will still honor retries before enacting this behavior.
      Parameters:
      faultTolerantRefresh - Whether to enable fault tolerant refresh behavior.
    • configureBackgroundRefresh

      public void configureBackgroundRefresh(boolean backgroundRefresh)
      If set to true, enables background refresh of expired cache entries. When an entry expires and a stale value exists, the cache will return the stale value immediately and trigger an asynchronous refresh in the background. This follows the "stale-while-revalidate" pattern to prevent blocking on cache refresh in high-concurrency scenarios. If no stale value exists (first fetch), falls back to synchronous refresh.
      Parameters:
      backgroundRefresh - Whether to enable background refresh behavior.
    • configureBackgroundRefreshExecutorThreads

      public void configureBackgroundRefreshExecutorThreads(long threads)
      Configures the number of threads in the background refresh executor pool. Only used when background refresh is enabled. The executor uses a fixed thread pool with daemon threads.
      Parameters:
      threads - The number of executor threads (must be positive).
    • configureBackgroundRefreshTimeout

      public void configureBackgroundRefreshTimeout(Duration timeout)
      Configures the timeout for background refresh operations. If a background refresh exceeds this timeout, it will be interrupted and the stale value will continue to be served.
      Parameters:
      timeout - The refresh timeout duration (must be non-negative).
    • configureGlobalIdKeyExtractor

      public void configureGlobalIdKeyExtractor(Function<V,Long> keyExtractor)
    • configureContentKeyExtractor

      public void configureContentKeyExtractor(Function<V,ContentWithReferences> keyExtractor)
    • configureContentIdKeyExtractor

      public void configureContentIdKeyExtractor(Function<V,Long> keyExtractor)
    • configureArtifactCoordinatesKeyExtractor

      public void configureArtifactCoordinatesKeyExtractor(Function<V,ArtifactCoordinates> keyExtractor)
    • configureContentHashKeyExtractor

      public void configureContentHashKeyExtractor(Function<V,String> keyExtractor)
    • isCacheLatest

      public boolean isCacheLatest()
      Return whether caching of artifact lookups with null versions is enabled.
      Returns:
      true if it's enabled.
      See Also:
    • isFaultTolerantRefresh

      public boolean isFaultTolerantRefresh()
      Return whether fault tolerant refresh is enabled.
      Returns:
      true if it's enabled.
      See Also:
    • isBackgroundRefresh

      public boolean isBackgroundRefresh()
      Return whether background refresh is enabled.
      Returns:
      true if it's enabled.
      See Also:
    • checkInitialized

      public void checkInitialized()
    • containsByGlobalId

      public boolean containsByGlobalId(Long key)
    • containsByContentId

      public boolean containsByContentId(Long key)
    • containsByArtifactCoordinates

      public boolean containsByArtifactCoordinates(ArtifactCoordinates key)
    • containsByArtifactCoordinatesMatchingContent

      public boolean containsByArtifactCoordinatesMatchingContent(ArtifactCoordinates key, ContentWithReferences expectedContent)
    • containsByContentHash

      public boolean containsByContentHash(String key)
    • getByGlobalId

      public V getByGlobalId(Long key, Function<Long,V> loaderFunction)
    • getByContent

      public V getByContent(ContentWithReferences key, Function<ContentWithReferences,V> loaderFunction)
    • getByContentId

      public V getByContentId(Long key, Function<Long,V> loaderFunction)
    • getByArtifactCoordinates

      public V getByArtifactCoordinates(ArtifactCoordinates key, Function<ArtifactCoordinates,V> loaderFunction)
    • getByContentHash

      public V getByContentHash(String key, Function<String,V> loaderFunction)
    • clear

      public void clear()
    • shutdown

      public void shutdown()
      Shuts down the background refresh executor if it exists. Waits for currently executing tasks to complete with a timeout. This method should be called when the cache is no longer needed to ensure proper cleanup of background threads.