Class CacheUtil

java.lang.Object
com.sure.tool.cache.CacheUtil

public class CacheUtil extends Object
缓存门面:快速创建各种策略缓存,参考 Hutool 的 CacheUtil 设计。

English: Factory and convenience methods for the built-in cache implementations.

Since:
0.1.0
Author:
suretool
  • Method Details

    • newFifoCache

      public static <K,V> FifoCache<K,V> newFifoCache(int capacity)
      创建 FIFO 缓存。
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      capacity - 容量
      Returns:
      缓存
    • newLruCache

      public static <K,V> LruCache<K,V> newLruCache(int capacity)
      创建 LRU 缓存。
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      capacity - 容量
      Returns:
      缓存
    • newLfuCache

      public static <K,V> LfuCache<K,V> newLfuCache(int capacity)
      创建 LFU 缓存。
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      capacity - 容量
      Returns:
      缓存
    • newTimedCache

      public static <K,V> TimedCache<K,V> newTimedCache(long defaultTimeout)
      创建定时过期缓存。
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      defaultTimeout - 默认存活时间(毫秒)
      Returns:
      缓存
    • newWeakCache

      public static <K,V> WeakCache<K,V> newWeakCache()
      创建弱引用缓存(值可被 GC 回收,自动清理)。
      Type Parameters:
      K - 键类型
      V - 值类型
      Returns:
      缓存
    • newWeakCache

      public static <K,V> WeakCache<K,V> newWeakCache(int capacity, long defaultTimeout)
      创建弱引用缓存。
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      capacity - 容量上限,<=0 表示无上限
      defaultTimeout - 默认存活时间(毫秒),<=0 表示不过期
      Returns:
      缓存