Interface Cache<K,V>

Type Parameters:
K - 键类型
V - 值类型
All Known Implementing Classes:
FifoCache, LfuCache, LruCache, TimedCache, WeakCache

public interface Cache<K,V>
缓存接口,参考 Hutool 的 Cache 设计。
Since:
0.1.0
Author:
suretool
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    清空缓存。
    boolean
    是否包含键(已过期视为不存在)。
    get(K key)
    读取缓存值,不存在或已过期返回 null。
    default V
    getOrPut(K key, Supplier<V> loader)
    读取缓存;不存在或已过期时通过 loader 计算并写入。
    boolean
    是否为空。
    put(K key, V value)
    写入缓存。
    remove(K key)
    移除缓存项。
    int
    缓存项数量。
  • Method Details

    • get

      V get(K key)
      读取缓存值,不存在或已过期返回 null。
      Parameters:
      key - 键
      Returns:
      值或 null
    • put

      V put(K key, V value)
      写入缓存。
      Parameters:
      key - 键
      value - 值
      Returns:
      被覆盖的旧值或 null
    • remove

      V remove(K key)
      移除缓存项。
      Parameters:
      key - 键
      Returns:
      被移除的值或 null
    • clear

      void clear()
      清空缓存。
    • size

      int size()
      缓存项数量。
      Returns:
      数量
    • containsKey

      boolean containsKey(K key)
      是否包含键(已过期视为不存在)。
      Parameters:
      key - 键
      Returns:
      是否包含
    • isEmpty

      boolean isEmpty()
      是否为空。
      Returns:
      是否为空
    • getOrPut

      default V getOrPut(K key, Supplier<V> loader)
      读取缓存;不存在或已过期时通过 loader 计算并写入。
      Parameters:
      key - 键
      loader - 值加载函数
      Returns:
      缓存值