Package org.cache2k.core.timing
Class StaticTiming<K,V>
- java.lang.Object
-
- org.cache2k.core.timing.Timing<K,V>
-
- org.cache2k.core.timing.StaticTiming<K,V>
-
- All Implemented Interfaces:
NeedsClose
public class StaticTiming<K,V> extends Timing<K,V>
Expiry time is constant- Author:
- Jens Wilke
-
-
Field Summary
Fields Modifier and Type Field Description protected org.cache2k.operation.TimeReferenceclockprotected longexpiryTicksprotected booleanrefreshAheadprotected org.cache2k.io.ResiliencePolicy<K,V>resiliencePolicystatic DurationSHARP_EXPIRY_SAFETY_GAPWhen sharp expiry is enabled, the expiry timer goes before the actual expiry to switch back to a time checking scheme when the cache is accessed.protected booleansharpExpiry
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longcacheExceptionUntil(Entry<K,V> e, org.cache2k.io.LoadExceptionInfo inf)Delegated to the resilience policylongcalculateNextRefreshTime(Entry<K,V> e, V value, long loadTime)Calculates the expiry time for a value that was just loaded or inserted into the cache.voidcancelAll()Cancels all pending timer events.voidcancelExpiryTimer(Entry<K,V> e)Cancel the timer on the entry, if a timer was set.voidclose(InternalCacheCloseContext closeContext)longgetExpiryAfterWriteTicks()longlimitExpiryTime(long now, long expiryTime)voidscheduleFinalTimerForSharpExpiry(Entry<K,V> e)Schedule second timer event for the expiry tie if sharp expiry is switched on.voidsetTarget(TimerEventListener<K,V> target)Set the target for timer events.booleanstartRefreshProbationTimer(Entry<K,V> e, long nextRefreshTime)Start probation timer.longstopStartTimer(long expiryTime, Entry<K,V> e)Calculate the needed timer value, which depends on the setting of sharpExpiry and refreshAhead.longsuppressExceptionUntil(Entry<K,V> e, org.cache2k.io.LoadExceptionInfo inf)Delegated to the resilience policy
-
-
-
Field Detail
-
SHARP_EXPIRY_SAFETY_GAP
public static final Duration SHARP_EXPIRY_SAFETY_GAP
When sharp expiry is enabled, the expiry timer goes before the actual expiry to switch back to a time checking scheme when the cache is accessed. This prevents that an expired value gets served by the cache when the time is too late. Experiments showed that a value of one second is usually sufficient.OS scheduling is not reliable on virtual servers (e.g. KVM) to give the expiry task compute time on a busy server. To be safe in extreme cases, this parameter is set to a high value.
-
clock
protected final org.cache2k.operation.TimeReference clock
-
sharpExpiry
protected final boolean sharpExpiry
-
refreshAhead
protected final boolean refreshAhead
-
expiryTicks
protected final long expiryTicks
-
-
Method Detail
-
setTarget
public void setTarget(TimerEventListener<K,V> target)
Description copied from class:TimingSet the target for timer events. Called during cache build before any timer tasks are created. For each cache instance there is a timing instance and both reference each other. We create timing first, then the cache.
-
cancelAll
public void cancelAll()
Description copied from class:TimingCancels all pending timer events.
-
close
public void close(InternalCacheCloseContext closeContext)
-
calculateNextRefreshTime
public long calculateNextRefreshTime(Entry<K,V> e, V value, long loadTime)
Description copied from class:TimingCalculates the expiry time for a value that was just loaded or inserted into the cache.- Specified by:
calculateNextRefreshTimein classTiming<K,V>- Parameters:
e- The entry, filled with the previous value if there is a value present already.value- The new value or an exception wrapped inExceptionWrapperloadTime- the time immediately before the load started- Returns:
- Point in time when the entry should expire. Meaning identical to
ExpiryPolicy.calculateExpiryTime(Object, Object, long, CacheEntry)
-
limitExpiryTime
public long limitExpiryTime(long now, long expiryTime)- Overrides:
limitExpiryTimein classTiming<K,V>
-
suppressExceptionUntil
public long suppressExceptionUntil(Entry<K,V> e, org.cache2k.io.LoadExceptionInfo inf)
Description copied from class:TimingDelegated to the resilience policy- Specified by:
suppressExceptionUntilin classTiming<K,V>- See Also:
ResiliencePolicy.suppressExceptionUntil(K, org.cache2k.io.LoadExceptionInfo<K, V>, org.cache2k.CacheEntry<K, V>)
-
cacheExceptionUntil
public long cacheExceptionUntil(Entry<K,V> e, org.cache2k.io.LoadExceptionInfo inf)
Description copied from class:TimingDelegated to the resilience policy- Specified by:
cacheExceptionUntilin classTiming<K,V>- See Also:
ResiliencePolicy.retryLoadAfter(K, org.cache2k.io.LoadExceptionInfo<K, V>)
-
stopStartTimer
public long stopStartTimer(long expiryTime, Entry<K,V> e)Calculate the needed timer value, which depends on the setting of sharpExpiry and refreshAhead. It may happen that the timer is not started, because the time is already passed. In this caseEntry.EXPIREDis returned. Callers need to check that and may be remove the entry consequently from the cache.- Overrides:
stopStartTimerin classTiming<K,V>- Parameters:
expiryTime- expiry time with special values as defined inExpiryTimeValuese- the entry- Returns:
- adjusted value for nextRefreshTime.
-
startRefreshProbationTimer
public boolean startRefreshProbationTimer(Entry<K,V> e, long nextRefreshTime)
Description copied from class:TimingStart probation timer.- Overrides:
startRefreshProbationTimerin classTiming<K,V>- Returns:
- true, if entry is finally expired.
-
scheduleFinalTimerForSharpExpiry
public void scheduleFinalTimerForSharpExpiry(Entry<K,V> e)
Description copied from class:TimingSchedule second timer event for the expiry tie if sharp expiry is switched on.- Overrides:
scheduleFinalTimerForSharpExpiryin classTiming<K,V>
-
cancelExpiryTimer
public void cancelExpiryTimer(Entry<K,V> e)
Description copied from class:TimingCancel the timer on the entry, if a timer was set.- Overrides:
cancelExpiryTimerin classTiming<K,V>
-
getExpiryAfterWriteTicks
public long getExpiryAfterWriteTicks()
- Overrides:
getExpiryAfterWriteTicksin classTiming<K,V>
-
-