🔄Update: 实现 HeavyKeeper 算法
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package cn.hezhaohui.thumb.manager.cache;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CacheManager {
|
||||
private TopK hotKeyDetector;
|
||||
private Cache<String, Object> localCache;
|
||||
|
||||
@Bean
|
||||
public TopK getHotKeyDetector() {
|
||||
return hotKeyDetector = new HeavyKeeper(
|
||||
// 监控 Top 100 Key
|
||||
100,
|
||||
// 宽度
|
||||
100000,
|
||||
// 深度
|
||||
5,
|
||||
// 衰减系数
|
||||
0.92,
|
||||
// 最小出现 10 次才记录
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Cache<String, Object> localCache() {
|
||||
return localCache = Caffeine.newBuilder()
|
||||
.maximumSize(1000)
|
||||
.expireAfterWrite(5, TimeUnit.MINUTES)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user