Class ExpiryPolicyBuilder<K,V>

java.lang.Object
org.ehcache.config.builders.ExpiryPolicyBuilder<K,V>
All Implemented Interfaces:
org.ehcache.config.Builder<org.ehcache.expiry.ExpiryPolicy<K,V>>

public final class ExpiryPolicyBuilder<K,V> extends Object implements org.ehcache.config.Builder<org.ehcache.expiry.ExpiryPolicy<K,V>>
Builder and utilities for getting predefined ExpiryPolicy instances.
  • Method Details

    • noExpiration

      public static org.ehcache.expiry.ExpiryPolicy<Object,Object> noExpiration()
      Get an ExpiryPolicy instance for a non expiring (ie. "eternal") cache.
      Returns:
      the no expiry instance
    • timeToLiveExpiration

      public static org.ehcache.expiry.ExpiryPolicy<Object,Object> timeToLiveExpiration(Duration timeToLive)
      Get a time-to-live (TTL) ExpiryPolicy instance for the given Duration.
      Parameters:
      timeToLive - the TTL duration
      Returns:
      a TTL expiry
    • timeToIdleExpiration

      public static org.ehcache.expiry.ExpiryPolicy<Object,Object> timeToIdleExpiration(Duration timeToIdle)
      Get a time-to-idle (TTI) ExpiryPolicy instance for the given Duration.
      Parameters:
      timeToIdle - the TTI duration
      Returns:
      a TTI expiry
    • expiry

      public static ExpiryPolicyBuilder<Object,Object> expiry()
      Fluent API for creating an ExpiryPolicy instance where you can specify constant values for creation, access and update time. Unspecified values will be set to INFINITE for create and null for access and update, matching the noExpiration() no expiration} expiry.
      Returns:
      an ExpiryPolicy builder
    • create

      public ExpiryPolicyBuilder<K,V> create(Duration create)
      Set TTL since creation.

      Note: Calling this method on a builder with an existing TTL since creation will override the previous value or function.

      Parameters:
      create - TTL since creation
      Returns:
      a new builder with the TTL since creation
    • create

      public <K2 extends K, V2 extends V> ExpiryPolicyBuilder<K2,V2> create(BiFunction<K2,V2,Duration> create)
      Set a function giving the TTL since creation.

      Note: Calling this method on a builder with an existing TTL since creation will override the previous value or function.

      Parameters:
      create - Function giving the TTL since creation
      Returns:
      a new builder with the TTL creation calculation function
    • access

      public ExpiryPolicyBuilder<K,V> access(Duration access)
      Set TTI since last access.

      Note: Calling this method on a builder with an existing TTI since last access will override the previous value or function.

      Parameters:
      access - TTI since last access
      Returns:
      a new builder with the TTI since last access
    • access

      public <K2 extends K, V2 extends V> ExpiryPolicyBuilder<K2,V2> access(BiFunction<K2,Supplier<? extends V2>,Duration> access)
      Set a function giving the TTI since last access.

      Note: Calling this method on a builder with an existing TTI since last access will override the previous value or function.

      Parameters:
      access - Function giving the TTI since last access
      Returns:
      a new builder with the TTI since last access calculation function
    • update

      public ExpiryPolicyBuilder<K,V> update(Duration update)
      Set TTL since last update.

      Note: Calling this method on a builder with an existing TTL since last access will override the previous value or function.

      Parameters:
      update - TTL since last update
      Returns:
      a new builder with the TTL since last update
    • update

      public <K2 extends K, V2 extends V> ExpiryPolicyBuilder<K2,V2> update(ExpiryPolicyBuilder.TriFunction<K2,Supplier<? extends V2>,V2,Duration> update)
      Set a function giving the TTL since last update.

      Note: Calling this method on a builder with an existing TTL since last update will override the previous value or function.

      Parameters:
      update - Function giving the TTL since last update
      Returns:
      a new builder with the TTL since last update calculation function
    • build

      public org.ehcache.expiry.ExpiryPolicy<K,V> build()
      Builds an expiry policy instance.
      Specified by:
      build in interface org.ehcache.config.Builder<K>
      Returns:
      an ExpiryPolicy