Interface Policy.FixedRefresh<K,V>

Type Parameters:
K - the type of keys
V - the type of values
Enclosing interface:
Policy<K,V>

public static interface Policy.FixedRefresh<K,V>
The low-level operations for a cache with a fixed refresh policy.
  • Method Summary

    Modifier and Type
    Method
    Description
    ageOf(K key)
    Returns the age of the entry based on the refresh policy.
    ageOf(K key, TimeUnit unit)
    Returns the age of the entry based on the refresh policy.
    default Duration
    Returns the fixed duration used to determine if an entry should be eligible for reloading due to elapsing this time bound.
    long
    Returns the fixed duration used to determine if an entry should be eligible for reloading due to elapsing this time bound.
    void
    setRefreshesAfter(long duration, TimeUnit unit)
    Specifies that each entry should be eligible for reloading once a fixed duration has elapsed.
    default void
    Specifies that each entry should be eligible for reloading once a fixed duration has elapsed.
  • Method Details

    • ageOf

      OptionalLong ageOf(K key, TimeUnit unit)
      Returns the age of the entry based on the refresh policy. The entry's age is the cache's estimate of the amount of time since the entry's refresh period was last reset.

      A refresh policy uses the age to determine if an entry is fresh or stale by comparing it to the freshness lifetime. This is calculated as fresh = freshnessLifetime > age where freshnessLifetime = expires - currentTime.

      Parameters:
      key - the key for the entry being queried
      unit - the unit that age is expressed in
      Returns:
      the age if the entry is present in the cache
      Throws:
      NullPointerException - if the specified key or unit is null
    • ageOf

      default Optional<Duration> ageOf(K key)
      Returns the age of the entry based on the refresh policy. The entry's age is the cache's estimate of the amount of time since the entry's refresh period was last reset.

      A refresh policy uses the age to determine if an entry is fresh or stale by comparing it to the freshness lifetime. This is calculated as fresh = freshnessLifetime > age where freshnessLifetime = expires - currentTime.

      Parameters:
      key - the key for the entry being queried
      Returns:
      the age if the entry is present in the cache
      Throws:
      NullPointerException - if the specified key is null
    • getRefreshesAfter

      long getRefreshesAfter(TimeUnit unit)
      Returns the fixed duration used to determine if an entry should be eligible for reloading due to elapsing this time bound. An entry is considered fresh if its age is less than this duration, and stale otherwise. The refresh policy determines when the entry's age is reset.
      Parameters:
      unit - the unit that duration is expressed in
      Returns:
      the length of time after which an entry is eligible to be reloaded
      Throws:
      NullPointerException - if the unit is null
    • getRefreshesAfter

      default Duration getRefreshesAfter()
      Returns the fixed duration used to determine if an entry should be eligible for reloading due to elapsing this time bound. An entry is considered fresh if its age is less than this duration, and stale otherwise. The refresh policy determines when the entry's age is reset.
      Returns:
      the length of time after which an entry is eligible to be reloaded
    • setRefreshesAfter

      void setRefreshesAfter(long duration, TimeUnit unit)
      Specifies that each entry should be eligible for reloading once a fixed duration has elapsed. The refresh policy determines when the entry's age is reset.
      Parameters:
      duration - the length of time after which an entry is eligible to be reloaded
      unit - the unit that duration is expressed in
      Throws:
      IllegalArgumentException - if duration is negative
      NullPointerException - if the unit is null
    • setRefreshesAfter

      default void setRefreshesAfter(Duration duration)
      Specifies that each entry should be eligible for reloading once a fixed duration has elapsed. The refresh policy determines when the entry's age is reset.
      Parameters:
      duration - the length of time after which an entry is eligible to be reloaded
      Throws:
      IllegalArgumentException - if duration is negative
      NullPointerException - if the duration is null