Class ERCache<V>
java.lang.Object
io.apicurio.registry.resolver.cache.ERCache<V>
Expiration and Retry Cache
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidclear()voidconfigureArtifactCoordinatesKeyExtractor(Function<V, ArtifactCoordinates> keyExtractor) voidconfigureBackgroundRefresh(boolean backgroundRefresh) If set totrue, enables background refresh of expired cache entries.voidconfigureBackgroundRefreshExecutorThreads(long threads) Configures the number of threads in the background refresh executor pool.voidConfigures the timeout for background refresh operations.voidconfigureCacheLatest(boolean cacheLatest) Iftrue, will cache schema lookups that either have `latest` or no version specified.voidconfigureContentHashKeyExtractor(Function<V, String> keyExtractor) voidconfigureContentIdKeyExtractor(Function<V, Long> keyExtractor) voidconfigureContentKeyExtractor(Function<V, ContentWithReferences> keyExtractor) voidconfigureFaultTolerantRefresh(boolean faultTolerantRefresh) If set totrue, will log the load error instead of throwing it when an exception occurs trying to refresh a cache entry.voidconfigureGlobalIdKeyExtractor(Function<V, Long> keyExtractor) voidconfigureLifetime(Duration lifetime) voidconfigureRetryBackoff(Duration backoff) voidconfigureRetryCount(long retries) booleanbooleancontainsByArtifactCoordinatesMatchingContent(ArtifactCoordinates key, ContentWithReferences expectedContent) booleanbooleancontainsByContentId(Long key) booleancontainsByGlobalId(Long key) getByArtifactCoordinates(ArtifactCoordinates key, Function<ArtifactCoordinates, V> loaderFunction) getByContent(ContentWithReferences key, Function<ContentWithReferences, V> loaderFunction) getByContentHash(String key, Function<String, V> loaderFunction) getByContentId(Long key, Function<Long, V> loaderFunction) getByGlobalId(Long key, Function<Long, V> loaderFunction) booleanReturn whether background refresh is enabled.booleanReturn whether caching of artifact lookups withnullversions is enabled.booleanReturn whether fault tolerant refresh is enabled.voidshutdown()Shuts down the background refresh executor if it exists.
-
Constructor Details
-
ERCache
public ERCache()
-
-
Method Details
-
configureLifetime
-
configureRetryBackoff
-
configureRetryCount
public void configureRetryCount(long retries) -
configureCacheLatest
public void configureCacheLatest(boolean cacheLatest) Iftrue, 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 totrue, 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 totrue, 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
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
-
configureContentKeyExtractor
-
configureContentIdKeyExtractor
-
configureArtifactCoordinatesKeyExtractor
-
configureContentHashKeyExtractor
-
isCacheLatest
public boolean isCacheLatest()Return whether caching of artifact lookups withnullversions is enabled.- Returns:
trueif it's enabled.- See Also:
-
isFaultTolerantRefresh
public boolean isFaultTolerantRefresh()Return whether fault tolerant refresh is enabled.- Returns:
trueif it's enabled.- See Also:
-
isBackgroundRefresh
public boolean isBackgroundRefresh()Return whether background refresh is enabled.- Returns:
trueif it's enabled.- See Also:
-
checkInitialized
public void checkInitialized() -
containsByGlobalId
-
containsByContentId
-
containsByArtifactCoordinates
-
containsByArtifactCoordinatesMatchingContent
public boolean containsByArtifactCoordinatesMatchingContent(ArtifactCoordinates key, ContentWithReferences expectedContent) -
containsByContentHash
-
getByGlobalId
-
getByContent
-
getByContentId
-
getByArtifactCoordinates
public V getByArtifactCoordinates(ArtifactCoordinates key, Function<ArtifactCoordinates, V> loaderFunction) -
getByContentHash
-
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.
-