Package com.xxl.tool.cache
Class CacheTool<K,V>
java.lang.Object
com.xxl.tool.cache.CacheTool<K,V>
- Type Parameters:
K- cache key typeV- cache value type
Cache Tool
- Author:
- xuxueli 2018-01-22
-
Field Summary
FieldsModifier and TypeFieldDescription缓存实现实例protected CacheType缓存类型protected int缓存容量,0表示无限制protected boolean缓存过期方式: - true: expireAfterWrite , 从缓存写入开始计算,有效期到期则被清除 - false: expireAfterAccess, 从缓存最后一次访问开始计算,有效期到期则被清除protected CacheListener<K,V> 缓存变更(删除)监听器protected CacheLoader<K,V> 缓存对象创建组件protected long定时清理延时,0表示不启用,单位:毫秒protected ScheduledFuture<?>定时清理任务protected long缓存有效期,0表示无限制,单位毫秒 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<K,V> Cache<K, V> build()build cache设置 缓存类型capacity(int capacity) 设置 容量expireAfterAccess(long timeout) 设置 过期时长expireAfterWrite(long timeout) 设置 过期时长listener(CacheListener<K, V> listener) 设置 缓存变更(删除)监听器loader(CacheLoader<K, V> cacheLoader) 设置 缓存对象创建组件static <K,V> CacheTool<K, V> newCache()new cachestatic <K,V> CacheTool<K, V> FIFO cachestatic <K,V> CacheTool<K, V> newFIFOCache(int capacity) FIFO cachestatic <K,V> CacheTool<K, V> LFU cachestatic <K,V> CacheTool<K, V> newLFUCache(int capacity) LFU cachestatic <K,V> CacheTool<K, V> LRU cachestatic <K,V> CacheTool<K, V> newLRUCache(int capacity) LRU cachestatic <K,V> CacheTool<K, V> 无容量限制static <K,V> CacheTool<K, V> newUnlimitedCache(int timeout) 无容量限制pruneInterval(long pruneInterval) 设置 定时清理延时, 单位:毫秒voidstop()stop
-
Field Details
-
timeout
protected long timeout缓存有效期,0表示无限制,单位毫秒 -
expireType
protected boolean expireType缓存过期方式: - true: expireAfterWrite , 从缓存写入开始计算,有效期到期则被清除 - false: expireAfterAccess, 从缓存最后一次访问开始计算,有效期到期则被清除 -
capacity
protected int capacity缓存容量,0表示无限制 -
cacheType
缓存类型 -
loader
缓存对象创建组件 -
listener
缓存变更(删除)监听器 -
pruneInterval
protected long pruneInterval定时清理延时,0表示不启用,单位:毫秒 -
pruneJobFuture
定时清理任务 -
cache
缓存实现实例
-
-
Constructor Details
-
CacheTool
public CacheTool()
-
-
Method Details
-
newCache
new cache- Returns:
- CacheTool
-
newFIFOCache
FIFO cache- Returns:
- CacheTool
-
newFIFOCache
FIFO cache- Parameters:
capacity- capacity of cache- Returns:
- CacheTool
-
newLRUCache
LRU cache- Returns:
- CacheTool
-
newLRUCache
LRU cache- Parameters:
capacity- capacity of cache- Returns:
- CacheTool
-
newLFUCache
LFU cache- Returns:
- CacheTool
-
newLFUCache
LFU cache- Parameters:
capacity- capacity of cache- Returns:
- CacheTool
-
newUnlimitedCache
无容量限制- Returns:
- CacheTool
-
newUnlimitedCache
无容量限制- Parameters:
timeout- timeout of cache, for millisecond- Returns:
- CacheTool
-
expireAfterWrite
设置 过期时长 -
expireAfterAccess
设置 过期时长 -
capacity
设置 容量 -
cache
设置 缓存类型 -
loader
设置 缓存对象创建组件 -
listener
设置 缓存变更(删除)监听器 -
pruneInterval
设置 定时清理延时, 单位:毫秒 -
build
build cache -
stop
public void stop()stop
-