Class StaticTiming<K,​V>

  • All Implemented Interfaces:
    NeedsClose

    public class StaticTiming<K,​V>
    extends Timing<K,​V>
    Expiry time is constant
    Author:
    Jens Wilke
    • 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.

      • resiliencePolicy

        protected final org.cache2k.io.ResiliencePolicy<K,​V> resiliencePolicy
      • 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: Timing
        Set 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.
        Overrides:
        setTarget in class Timing<K,​V>
      • cancelAll

        public void cancelAll()
        Description copied from class: Timing
        Cancels all pending timer events.
        Overrides:
        cancelAll in class Timing<K,​V>
      • calculateNextRefreshTime

        public long calculateNextRefreshTime​(Entry<K,​V> e,
                                             V value,
                                             long loadTime)
        Description copied from class: Timing
        Calculates the expiry time for a value that was just loaded or inserted into the cache.
        Specified by:
        calculateNextRefreshTime in class Timing<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 in ExceptionWrapper
        loadTime - 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:
        limitExpiryTime in class Timing<K,​V>
      • suppressExceptionUntil

        public long suppressExceptionUntil​(Entry<K,​V> e,
                                           org.cache2k.io.LoadExceptionInfo inf)
        Description copied from class: Timing
        Delegated to the resilience policy
        Specified by:
        suppressExceptionUntil in class Timing<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: Timing
        Delegated to the resilience policy
        Specified by:
        cacheExceptionUntil in class Timing<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 case Entry.EXPIRED is returned. Callers need to check that and may be remove the entry consequently from the cache.
        Overrides:
        stopStartTimer in class Timing<K,​V>
        Parameters:
        expiryTime - expiry time with special values as defined in ExpiryTimeValues
        e - the entry
        Returns:
        adjusted value for nextRefreshTime.
      • startRefreshProbationTimer

        public boolean startRefreshProbationTimer​(Entry<K,​V> e,
                                                  long nextRefreshTime)
        Description copied from class: Timing
        Start probation timer.
        Overrides:
        startRefreshProbationTimer in class Timing<K,​V>
        Returns:
        true, if entry is finally expired.
      • scheduleFinalTimerForSharpExpiry

        public void scheduleFinalTimerForSharpExpiry​(Entry<K,​V> e)
        Description copied from class: Timing
        Schedule second timer event for the expiry tie if sharp expiry is switched on.
        Overrides:
        scheduleFinalTimerForSharpExpiry in class Timing<K,​V>
      • cancelExpiryTimer

        public void cancelExpiryTimer​(Entry<K,​V> e)
        Description copied from class: Timing
        Cancel the timer on the entry, if a timer was set.
        Overrides:
        cancelExpiryTimer in class Timing<K,​V>