Class CacheTool<K,V>

java.lang.Object
com.xxl.tool.cache.CacheTool<K,V>
Type Parameters:
K - cache key type
V - cache value type

public class CacheTool<K,V> extends Object
Cache Tool
Author:
xuxueli 2018-01-22
  • Field Details

    • timeout

      protected long timeout
      缓存有效期,0 表示无限制,单位毫秒
    • expireType

      protected boolean expireType
      缓存过期方式: - true: expireAfterWrite , 从缓存写入开始计算,有效期到期则被清除 - false: expireAfterAccess, 从缓存最后一次访问开始计算,有效期到期则被清除
    • capacity

      protected int capacity
      缓存容量, 0 表示无限制
    • cacheType

      protected CacheType cacheType
      缓存类型
    • loader

      protected CacheLoader<K,V> loader
      缓存对象创建组件
    • listener

      protected CacheListener<K,V> listener
      缓存变更(删除)监听器
    • pruneInterval

      protected long pruneInterval
      定时清理延时,0 表示不启用,单位:毫秒
    • pruneJobFuture

      protected ScheduledFuture<?> pruneJobFuture
      定时清理任务
    • cache

      protected Cache<K,V> cache
      缓存实现实例
  • Constructor Details

    • CacheTool

      public CacheTool()
  • Method Details

    • newCache

      public static <K, V> CacheTool<K,V> newCache()
      new cache
      Returns:
      CacheTool
    • newFIFOCache

      public static <K, V> CacheTool<K,V> newFIFOCache()
      FIFO cache
      Returns:
      CacheTool
    • newFIFOCache

      public static <K, V> CacheTool<K,V> newFIFOCache(int capacity)
      FIFO cache
      Parameters:
      capacity - capacity of cache
      Returns:
      CacheTool
    • newLRUCache

      public static <K, V> CacheTool<K,V> newLRUCache()
      LRU cache
      Returns:
      CacheTool
    • newLRUCache

      public static <K, V> CacheTool<K,V> newLRUCache(int capacity)
      LRU cache
      Parameters:
      capacity - capacity of cache
      Returns:
      CacheTool
    • newLFUCache

      public static <K, V> CacheTool<K,V> newLFUCache()
      LFU cache
      Returns:
      CacheTool
    • newLFUCache

      public static <K, V> CacheTool<K,V> newLFUCache(int capacity)
      LFU cache
      Parameters:
      capacity - capacity of cache
      Returns:
      CacheTool
    • newUnlimitedCache

      public static <K, V> CacheTool<K,V> newUnlimitedCache()
      无容量限制
      Returns:
      CacheTool
    • newUnlimitedCache

      public static <K, V> CacheTool<K,V> newUnlimitedCache(int timeout)
      无容量限制
      Parameters:
      timeout - timeout of cache, for millisecond
      Returns:
      CacheTool
    • expireAfterWrite

      public CacheTool<K,V> expireAfterWrite(long timeout)
      设置 过期时长
    • expireAfterAccess

      public CacheTool<K,V> expireAfterAccess(long timeout)
      设置 过期时长
    • capacity

      public CacheTool<K,V> capacity(int capacity)
      设置 容量
    • cache

      public CacheTool<K,V> cache(CacheType cacheType)
      设置 缓存类型
    • loader

      public CacheTool<K,V> loader(CacheLoader<K,V> cacheLoader)
      设置 缓存对象创建组件
    • listener

      public CacheTool<K,V> listener(CacheListener<K,V> listener)
      设置 缓存变更(删除)监听器
    • pruneInterval

      public CacheTool<K,V> pruneInterval(long pruneInterval)
      设置 定时清理延时, 单位:毫秒
    • build

      public <K, V> Cache<K,V> build()
      build cache
    • stop

      public void stop()
      stop