Interface ResiliencePolicy<K,V>
-
- All Superinterfaces:
Customization
,DataAware<K,V>
,DataAwareCustomization<K,V>
,ExpiryTimeValues
public interface ResiliencePolicy<K,V> extends ExpiryTimeValues, DataAwareCustomization<K,V>
Controls how to deal with loader exceptions in a read through configuration. An exception can be cached and propagated or the cache can fall back to the currently cached value if a previous load attempt did complete successful.- Since:
- 2
- Author:
- Jens Wilke
-
-
Field Summary
Fields Modifier and Type Field Description static ResiliencePolicy<?,?>
DISABLED_POLICY
A policy always returning zero, thus disabling resilience features.-
Fields inherited from interface org.cache2k.expiry.ExpiryTimeValues
ETERNAL, NEUTRAL, NOW, REFRESH
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static <K,V>
voiddisable(Cache2kBuilder<K,V> b)
static <K,V>
ResiliencePolicy<K,V>disabledPolicy()
long
retryLoadAfter(K key, LoadExceptionInfo<K,V> loadExceptionInfo)
Called after the loader threw an exception and no previous value is available orsuppressExceptionUntil(K, org.cache2k.io.LoadExceptionInfo<K, V>, org.cache2k.CacheEntry<K, V>)
returned zero.long
suppressExceptionUntil(K key, LoadExceptionInfo<K,V> loadExceptionInfo, CacheEntry<K,V> cachedEntry)
Called after the loader threw an exception and a previous value is available.
-
-
-
Field Detail
-
DISABLED_POLICY
static final ResiliencePolicy<?,?> DISABLED_POLICY
A policy always returning zero, thus disabling resilience features. This is also used as default when no resilience policy is set.
-
-
Method Detail
-
disabledPolicy
static <K,V> ResiliencePolicy<K,V> disabledPolicy()
-
disable
static <K,V> void disable(Cache2kBuilder<K,V> b)
-
suppressExceptionUntil
long suppressExceptionUntil(K key, LoadExceptionInfo<K,V> loadExceptionInfo, CacheEntry<K,V> cachedEntry)
Called after the loader threw an exception and a previous value is available. Returns a point in time determining how long the exceptions should be suppressed, or in other words, until when the previous loaded value should be returned by the cache.The returned value is a point in time. If the currently cached content is expired, returning a future time will effectively extend the entry expiry.
If
Cache2kBuilder.expireAfterWrite(long, TimeUnit)
is specified, the maximum duration will be capped with the specified value.Returning 0 or a time in the past means the exception should not be suppressed. The cache will call immediately
retryLoadAfter(K, org.cache2k.io.LoadExceptionInfo<K, V>)
to determine how long the exception should stay in the cache and when the next retry attempt takes place.If the exception is not suppressed, it will be wrapped into a
CacheLoaderException
and propagated to the cache client. This is customizable by theExceptionPropagator
.- Parameters:
cachedEntry
- The entry representing the currently cached content. It is possible that this data is already expired. This entry never contains an exception.- Returns:
- Time in the future when the content should expire again. A zero or
a time before the current time means the exception will not be suppressed. A
ExpiryTimeValues.ETERNAL
means the exception will be suppressed and the recent content will be returned eternally. If the returned time is afterLoadExceptionInfo.getLoadTime()
the exception will be suppressed for the ongoing operation.
-
retryLoadAfter
long retryLoadAfter(K key, LoadExceptionInfo<K,V> loadExceptionInfo)
Called after the loader threw an exception and no previous value is available orsuppressExceptionUntil(K, org.cache2k.io.LoadExceptionInfo<K, V>, org.cache2k.CacheEntry<K, V>)
returned zero. Returns a point in time until then an exception will be cached.If
Cache2kBuilder.expireAfterWrite(long, TimeUnit)
is specified, the maximum duration will be capped with the specified value.- Returns:
- Time in the future when the exception should expire. A zero or
a time before the current time means the exception will not be cached and
a new load is triggered by the next
get()
. AExpiryTimeValues.ETERNAL
means the exception will be cached forever.
-
-