类 LettuceCache<K,V>
- java.lang.Object
-
- cn.sliew.milky.cache.lettuce.LettuceCache<K,V>
-
- 所有已实现的接口:
Cache<K,V>
public class LettuceCache<K,V> extends Object implements Cache<K,V>
redis缓存没有使用常用的strings类型来搞 使用了hash作为缓存存储模式带来一个问题:redis官方至今没有打算支持hash的field的ttl。 因此需要自己实现针对hash的field的ttl。 为value对象创建包装类ValueWrapper,记录过期时间戳。获取缓存对象的时候查看对象是否已经过期。 对于每个key对象放入一个sortset,以过期时间戳作为分数,创建定时任务定期从sortset和hash 中移除缓存对象。 为了保证数据不会出现永久停留在redis中的问题,设置缓存的过期时间统一为凌晨3点,缓存的凌晨过期 不会造成业务的突然抖动,也能定时清理所有的缓存对象 todo 考虑到对象双写的问题,需要将同时操作sortset和hash的对象移除功能处理为一个 todo 原子操作,需要使用lua脚本来搞。时间轮是一秒跳一次,每个任务执行完毕后设置的是一秒后执行下一个任务,因此最快两个任务的执行间隔为2s。 回头需要研究下spring中的redis cache是如何操作的。
-
-
嵌套类概要
嵌套类 修饰符和类型 类 说明 static classLettuceCache.ValueWrapper<V>
-
构造器概要
构造器 构造器 说明 LettuceCache(LettuceCacheOptions<K,V> options)
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidclear()VcomputeIfAbsent(K key, CacheLoader<K,V> loader, Duration expire)booleancontainsKey(K key)voiddestroy()Vget(K key)Iterator<K>hotKeyIterator(int n)Iterator<K>keyIterator()fixme hkeys hscan todo 考虑使用sortset的key来搞。Stringname()voidput(K key, V value)voidput(K key, V value, Duration expire)voidremove(K key)voidremoveAll(Iterable<K> keys)longsize()voidstats(io.micrometer.core.instrument.MeterRegistry registry)fixme 数据监控booleansupportNullKey()booleansupportNullValue()
-
-
-
构造器详细资料
-
LettuceCache
public LettuceCache(LettuceCacheOptions<K,V> options)
-
-
方法详细资料
-
containsKey
public boolean containsKey(K key)
- 指定者:
containsKey在接口中Cache<K,V>
-
computeIfAbsent
public V computeIfAbsent(K key, CacheLoader<K,V> loader, Duration expire)
- 指定者:
computeIfAbsent在接口中Cache<K,V>
-
supportNullKey
public boolean supportNullKey()
- 指定者:
supportNullKey在接口中Cache<K,V>
-
supportNullValue
public boolean supportNullValue()
- 指定者:
supportNullValue在接口中Cache<K,V>
-
keyIterator
public Iterator<K> keyIterator()
fixme hkeys hscan todo 考虑使用sortset的key来搞。zscan- 指定者:
keyIterator在接口中Cache<K,V>
-
stats
public void stats(io.micrometer.core.instrument.MeterRegistry registry)
fixme 数据监控
-
-