Interface TimeCache<K,​V>

  • Type Parameters:
    K - 键的类型
    V - 值的类型
    All Superinterfaces:
    CommonCache<K,​V>
    All Known Subinterfaces:
    PersistCache<K,​V>

    public interface TimeCache<K,​V>
    extends CommonCache<K,​V>
    缓存键值对数据, 可以对键值对设置存活时间
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default V computeIfAbsent​(K key, java.util.function.Function<? super K,​? extends V> mapping, long alive)
      获取或映射一个
      long expire​(K key)
      获取对应键的过期时间
      V get​(K key, long alive)
      获取键对应的值
      V get​(K key, long timeout, java.util.concurrent.TimeUnit unit)
      获取键对应的值
      V get​(K key, java.time.Instant expire)
      获取键对应的值
      default V get​(K key, java.util.function.Supplier<V> supplier, long alive)
      获取或生成
      boolean has​(K key, long alive)
      是否存在某个键
      boolean has​(K key, long timeout, java.util.concurrent.TimeUnit unit)
      是否存在某个键
      boolean has​(K key, java.time.Instant expire)
      是否存在某个键
      long last​(K key)
      获取对应键的剩余存活时间
      default V putIfAbsent​(K key, V value, long alive)
      若不存在则存入
      void set​(K key, V value, long alive)
      新增或更新一个键值对
      void set​(K key, V value, long timeout, java.util.concurrent.TimeUnit unit)
      新增或更新一个键值对
      void set​(K key, V value, java.time.Instant expire)
      新增或更新一个键值对
    • Method Detail

      • set

        void set​(K key,
                 V value,
                 java.time.Instant expire)
        新增或更新一个键值对
        Parameters:
        key - 键
        value - 值
        expire - 过期时刻
      • set

        void set​(K key,
                 V value,
                 long timeout,
                 java.util.concurrent.TimeUnit unit)
        新增或更新一个键值对
        Parameters:
        key - 键
        value - 值
        timeout - 超时时间
        unit - 时间单位
      • set

        void set​(K key,
                 V value,
                 long alive)
        新增或更新一个键值对
        Parameters:
        key - 键
        value - 值
        alive - 存活毫秒数, 若为负数, 表明永不过期
      • has

        boolean has​(K key,
                    java.time.Instant expire)
        是否存在某个键
        Parameters:
        key - 键
        expire - 若存在, 更新过期时刻
        Returns:
        存在返回 true, 不存在返回 false
      • has

        boolean has​(K key,
                    long timeout,
                    java.util.concurrent.TimeUnit unit)
        是否存在某个键
        Parameters:
        key - 键
        timeout - 若存在, 更新超时时间
        unit - 时间单位
        Returns:
        存在返回 true, 不存在返回 false
      • has

        boolean has​(K key,
                    long alive)
        是否存在某个键
        Parameters:
        key - 键
        alive - 若存在, 更新存活毫秒数, 若为负数, 表明永不过期
        Returns:
        存在返回 true, 不存在返回 false
      • get

        V get​(K key,
              java.time.Instant expire)
        获取键对应的值
        Parameters:
        key - 键
        expire - 若存在, 更新过期时刻
        Returns:
        存在返回对应的值, 不存在返回 null
      • get

        V get​(K key,
              long timeout,
              java.util.concurrent.TimeUnit unit)
        获取键对应的值
        Parameters:
        key - 键
        timeout - 若存在, 更新超时时间
        unit - 时间单位
        Returns:
        存在返回对应的值, 不存在返回 null
      • get

        V get​(K key,
              long alive)
        获取键对应的值
        Parameters:
        key - 键
        alive - 若存在, 更新存活毫秒数, 若为负数, 表明永不过期
        Returns:
        存在返回对应的值, 不存在返回 null
      • expire

        long expire​(K key)
        获取对应键的过期时间
        Parameters:
        key - 键
        Returns:
        过期时间, 单位毫秒, 若不存在, 返回 0
      • last

        long last​(K key)
        获取对应键的剩余存活时间
        Parameters:
        key - 键
        Returns:
        剩余存活时间, 单位毫秒, 若不存在, 返回 0
      • putIfAbsent

        default V putIfAbsent​(K key,
                              V value,
                              long alive)
        若不存在则存入
        Parameters:
        key - 键
        value - 值
        alive - 若存在, 更新存活毫秒数, 若为负数, 表明永不过期
        Returns:
      • get

        default V get​(K key,
                      java.util.function.Supplier<V> supplier,
                      long alive)
        获取或生成
        Parameters:
        key - 键
        supplier - 生产者
        alive - 若存在, 更新存活毫秒数, 若为负数, 表明永不过期
        Returns:
      • computeIfAbsent

        default V computeIfAbsent​(K key,
                                  java.util.function.Function<? super K,​? extends V> mapping,
                                  long alive)
        获取或映射一个
        Parameters:
        key - 键
        mapping - 映射
        alive - 若存在, 更新存活毫秒数, 若为负数, 表明永不过期
        Returns: