Interface Cache<K,V>

Type Parameters:
K -
V -
All Superinterfaces:
Serializable
All Known Implementing Classes:
FIFOCache, LFUCache, LRUCache, NoCache, ReentrantCache, UnlimitedCache

public interface Cache<K,V> extends Serializable
Cache Interface
  • Method Summary

    Modifier and Type
    Method
    Description
    返回 键-值 映射,仅包括有效数据
    int
    缓存容量, 0 表示无限制
    void
    清空缓存对象
    boolean
    是否包含key
    get(K key)
    获取缓存对象
    get(K key, CacheLoader<K,V> cacheLoader)
    获取缓存对象
    获取缓存对象
    long
     
    boolean
    缓存是否为空
    boolean
    缓存是否已满,仅用于有空间限制的缓存对象
    long
     
    int
    清理过期缓存对象
    void
    put(K key, V object)
    设置缓存对象
    void
    remove(K key)
    删除单个缓存对象
    default Cache<K,V>
    设置监听
    default Cache<K,V>
    setLoader(CacheLoader<K,V> listener)
    设置监听
    int
    缓存对象数量
    long
    缓存有效期,0 表示无限制,单位毫秒
  • Method Details

    • put

      void put(K key, V object)
      设置缓存对象
      Parameters:
      key - 健
      object - 值对象
    • get

      V get(K key)
      获取缓存对象

      1、缓存对象不存在 或 已过期:尝试使用 cacheLoader 加载并返回对象,如果 cacheLoader 不存在返回 null 2、每次调用此方法会刷新最后访问时间,即重新计算超时时间

      Parameters:
      key - 键
      Returns:
      值对象
    • getIfPresent

      V getIfPresent(K key)
      获取缓存对象

      1、缓存对象不存在 或 已过期:直接返回 null 2、每次调用此方法会刷新最后访问时间,即重新计算超时时间

      Parameters:
      key - 键
      Returns:
      值对象
    • get

      V get(K key, CacheLoader<K,V> cacheLoader)
      获取缓存对象

      1、缓存对象不存在 或 已过期:使用 cacheLoader 加载并返回对象 2、每次调用此方法,可选是否 刷新最后访问时间,即重新计算超时时间

      Parameters:
      key - 键
      cacheLoader - 回调方法,用于生产值对象
      Returns:
      值对象
    • containsKey

      boolean containsKey(K key)
      是否包含key
      Parameters:
      key - 键
      Returns:
      值对象
    • asMap

      Map<K,V> asMap()
      返回 键-值 映射,仅包括有效数据
      Returns:
      键-值 映射(过滤已过期数据)
    • size

      int size()
      缓存对象数量

      1、包含过期数据

    • isFull

      boolean isFull()
      缓存是否已满,仅用于有空间限制的缓存对象

      1、包含过期数据

    • isEmpty

      boolean isEmpty()
      缓存是否为空

      1、包含过期数据

    • remove

      void remove(K key)
      删除单个缓存对象
      Parameters:
      key - 键
    • prune

      int prune()
      清理过期缓存对象
    • clear

      void clear()
      清空缓存对象
    • hitCount

      long hitCount()
      Returns:
      命中数
    • missCount

      long missCount()
      Returns:
      丢失数
    • capacity

      int capacity()
      缓存容量, 0 表示无限制
    • timeout

      long timeout()
      缓存有效期,0 表示无限制,单位毫秒
    • setListener

      default Cache<K,V> setListener(CacheListener<K,V> listener)
      设置监听
    • setLoader

      default Cache<K,V> setLoader(CacheLoader<K,V> listener)
      设置监听