Modifier and Type | Field and Description |
---|---|
protected static HashWheelTimer |
CACHE_MAP_WHEEL_TIMER |
Constructor and Description |
---|
CacheMap()
构造函数
|
CacheMap(Integer maxSize)
构造函数
|
CacheMap(Map<K,V> map) |
CacheMap(Map<K,V> map,
int maxSize)
构造函数
|
Modifier and Type | Method and Description |
---|---|
CacheMap<K,V> |
autoRemove(boolean autoRemove)
设置失效是否自动移除
|
void |
checkAndDoExpire(K key)
检查指定的Key, 如果过期则处理过期的数据
|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
CacheMap<K,V> |
create()
创建CachedHashMap
|
CacheMap<K,V> |
destory(BiFunction<K,V,Long> destory)
设置对象销毁函数
|
Set<Map.Entry<K,V>> |
entrySet() |
CacheMap<K,V> |
expire(long expire)
设置默认超时时间
|
V |
get(Object key,
Function<K,V> appointedSupplier,
Long createExpire,
boolean refresh)
获取对象
不会刷新对象的时间戳
|
ConcurrentHashMap<K,org.voovan.tools.collection.CacheMap.TimeMark> |
getCacheMark()
获取缓存标记对象
|
BiFunction<K,V,Long> |
getDestory()
获取对象销毁函数
|
long |
getExpire()
获取默认超时时间
|
Function<K,V> |
getSupplier()
获取数据创建 Function 对象
|
long |
getTTL(K key)
为 Key 获取 key 的超时时间
|
CacheMap<K,V> |
interval(int interval)
设置最失效对象检查周期
|
boolean |
isEmpty() |
boolean |
isExpire(String key)
是否过期
|
Set<K> |
keySet() |
CacheMap<K,V> |
maxSize(int maxSize)
设置最大容量
|
V |
put(K key,
V value) |
V |
put(K key,
V value,
long expire)
写入对象
|
void |
putAll(Map<? extends K,? extends V> m) |
void |
putAll(Map<? extends K,? extends V> m,
long expire)
写入特定的整个 Map
|
V |
putIfAbsent(K key,
V value)
写入如果对象为空
|
V |
putIfAbsent(K key,
V value,
long expire)
写入如果对象为空
|
V |
remove(Object key) |
boolean |
remove(Object key,
Object value) |
boolean |
setTTL(K key,
long expire)
更新某个对象的超时时间
可以为某个没有配置超时时间的键值对配置超时时间
|
int |
size() |
CacheMap<K,V> |
supplier(Function<K,V> buildFunction)
设置数据创建 Function 对象, 默认数据失效时不移除数据
|
CacheMap<K,V> |
supplier(Function<K,V> buildFunction,
boolean autoRemove)
设置数据创建 Function 对象
|
Collection<V> |
values() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
get, get, get, getAndRefresh, getAndRefresh, getAndRefresh
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, replace, replace, replaceAll
protected static final HashWheelTimer CACHE_MAP_WHEEL_TIMER
public CacheMap(Map<K,V> map, int maxSize)
map
- 缓存数据的 Map 对象maxSize
- 最大元素数量public CacheMap(Integer maxSize)
maxSize
- 缓存集合的最大容量, 多余的数据会被移除public CacheMap()
public Function<K,V> getSupplier()
getSupplier
in interface ICacheMap<K,V>
public CacheMap<K,V> supplier(Function<K,V> buildFunction)
public CacheMap<K,V> supplier(Function<K,V> buildFunction, boolean autoRemove)
buildFunction
- Function 对象autoRemove
- 设置失效是否自动移除public BiFunction<K,V,Long> getDestory()
public CacheMap<K,V> destory(BiFunction<K,V,Long> destory)
destory
- 对象销毁函数,
1.返回 null 则刷新为默认超时时间
2.小于0 的数据, 则移除对象
3.大于0的数据则重新设置返回值为新的超时时间public CacheMap<K,V> maxSize(int maxSize)
maxSize
- 最大容量public CacheMap<K,V> interval(int interval)
interval
- 检查周期, 单位:秒, 小于零不做超时处理public CacheMap<K,V> autoRemove(boolean autoRemove)
autoRemove
- true: 自动移除, false: 并不自动移除public long getExpire()
public ConcurrentHashMap<K,org.voovan.tools.collection.CacheMap.TimeMark> getCacheMark()
public void checkAndDoExpire(K key)
key
- 检查的 Keypublic V get(Object key, Function<K,V> appointedSupplier, Long createExpire, boolean refresh)
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
public V putIfAbsent(K key, V value)
putIfAbsent
in interface Map<K,V>
key
- 键value
- 值public V putIfAbsent(K key, V value, long expire)
putIfAbsent
in interface ICacheMap<K,V>
key
- 键value
- 值expire
- 超时时间public boolean isExpire(String key)
key
- 是否过期public boolean setTTL(K key, long expire)
Copyright © 2020 Voovan. All rights reserved.