Interface ExpiringValueCache<K,​V>

  • Type Parameters:
    K - The type of keys that the cache supports.
    V - The type of values that the cache supports.

    public interface ExpiringValueCache<K,​V>
    A cache for values that have a limited validity period.
    • Method Detail

      • put

        void put​(K key,
                 V value,
                 Instant expirationTime)
        Puts a value to the cache.

        Any previous value for the key will be replaced with the new one.

        Parameters:
        key - The key under which the value is stored.
        value - The value to store.
        expirationTime - The point in time after which the value should be considered invalid.
        Throws:
        NullPointerException - if any of the parameters is null.
        IllegalArgumentException - if the expiration time is not in the future.
      • put

        void put​(K key,
                 V value,
                 Duration maxAge)
        Puts a value to the cache.

        Any previous value for the key will be replaced with the new one.

        Parameters:
        key - The key under which the value is stored.
        value - The value to store.
        maxAge - The duration (starting from now) after which the value should be considered invalid.
        Throws:
        NullPointerException - if any of the parameters is null.
        IllegalArgumentException - if the expiration time is not in the future.
      • get

        V get​(K key)
        Gets a value from the cache.
        Parameters:
        key - The key to get the value for.
        Returns:
        The value or null if no value exists for the key or if the value is expired.