Interface Policy.FixedExpiration<K,​V>

  • Enclosing interface:
    Policy<K,​V>

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

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default Optional<Duration> ageOf​(K key)
      Returns the age of the entry based on the expiration policy.
      OptionalLong ageOf​(K key, TimeUnit unit)
      Returns the age of the entry based on the expiration policy.
      default Duration getExpiresAfter()
      Returns the fixed duration used to determine if an entry should be automatically removed due to elapsing this time bound.
      @org.checkerframework.checker.index.qual.NonNegative long getExpiresAfter​(TimeUnit unit)
      Returns the fixed duration used to determine if an entry should be automatically removed due to elapsing this time bound.
      Map<K,​V> oldest​(@org.checkerframework.checker.index.qual.NonNegative int limit)
      Returns an unmodifiable snapshot Map view of the cache with ordered traversal.
      void setExpiresAfter​(@org.checkerframework.checker.index.qual.NonNegative long duration, TimeUnit unit)
      Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed.
      default void setExpiresAfter​(Duration duration)
      Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed.
      Map<K,​V> youngest​(@org.checkerframework.checker.index.qual.NonNegative int limit)
      Returns an unmodifiable snapshot Map view of the cache with ordered traversal.
    • Method Detail

      • ageOf

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

        An expiration 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.

        This method is scheduled for removal in version 3.0.0.

        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
      • ageOf

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

        An expiration 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
      • getExpiresAfter

        @org.checkerframework.checker.index.qual.NonNegative long getExpiresAfter​(TimeUnit unit)
        Returns the fixed duration used to determine if an entry should be automatically removed due to elapsing this time bound. An entry is considered fresh if its age is less than this duration, and stale otherwise. The expiration policy determines when the entry's age is reset.

        This method is scheduled for removal in version 3.0.0.

        Parameters:
        unit - the unit that duration is expressed in
        Returns:
        the length of time after which an entry should be automatically removed
      • getExpiresAfter

        default Duration getExpiresAfter()
        Returns the fixed duration used to determine if an entry should be automatically removed due to elapsing this time bound. An entry is considered fresh if its age is less than this duration, and stale otherwise. The expiration policy determines when the entry's age is reset.
        Returns:
        the length of time after which an entry should be automatically removed
      • setExpiresAfter

        void setExpiresAfter​(@org.checkerframework.checker.index.qual.NonNegative long duration,
                             TimeUnit unit)
        Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed. The expiration policy determines when the entry's age is reset.

        This method is scheduled for removal in version 3.0.0.

        Parameters:
        duration - the length of time after which an entry should be automatically removed
        unit - the unit that duration is expressed in
        Throws:
        IllegalArgumentException - if duration is negative
      • setExpiresAfter

        default void setExpiresAfter​(Duration duration)
        Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed. The expiration policy determines when the entry's age is reset.
        Parameters:
        duration - the length of time after which an entry should be automatically removed
        Throws:
        IllegalArgumentException - if duration is negative
      • oldest

        Map<K,​V> oldest​(@org.checkerframework.checker.index.qual.NonNegative int limit)
        Returns an unmodifiable snapshot Map view of the cache with ordered traversal. The order of iteration is from the entries most likely to expire (oldest) to the entries least likely to expire (youngest). This order is determined by the expiration policy's best guess at the time of creating this snapshot view.

        Beware that obtaining the mappings is NOT a constant-time operation. Because of the asynchronous nature of the page replacement policy, determining the retention ordering requires a traversal of the entries.

        Parameters:
        limit - the maximum size of the returned map (use Integer.MAX_VALUE to disregard the limit)
        Returns:
        a snapshot view of the cache from oldest entry to the youngest
      • youngest

        Map<K,​V> youngest​(@org.checkerframework.checker.index.qual.NonNegative int limit)
        Returns an unmodifiable snapshot Map view of the cache with ordered traversal. The order of iteration is from the entries least likely to expire (youngest) to the entries most likely to expire (oldest). This order is determined by the expiration policy's best guess at the time of creating this snapshot view.

        Beware that obtaining the mappings is NOT a constant-time operation. Because of the asynchronous nature of the page replacement policy, determining the retention ordering requires a traversal of the entries.

        Parameters:
        limit - the maximum size of the returned map (use Integer.MAX_VALUE to disregard the limit)
        Returns:
        a snapshot view of the cache from youngest entry to the oldest