Class AccessPatternAnalyzer<K>
java.lang.Object
cloud.opencode.base.cache.analysis.AccessPatternAnalyzer<K>
- Type Parameters:
K- key type | 键类型Security | 安全性:
- Thread-safe: Yes (uses ConcurrentHashMap and atomic counters) - 线程安全: 是(使用 ConcurrentHashMap 和原子计数器)
- Null-safe: Yes - 空值安全: 是
Access Pattern Analyzer - Analyzes cache access patterns
访问模式分析器 - 分析缓存访问模式
Tracks and analyzes cache access patterns to identify hot keys, cold data, and optimize cache performance.
跟踪和分析缓存访问模式以识别热点键、冷数据,并优化缓存性能。
Features | 主要功能:
- Hot key detection - 热点键检测
- Cold data identification - 冷数据识别
- Access frequency tracking - 访问频率跟踪
- Temporal pattern analysis - 时间模式分析
- Top-K tracking - Top-K 跟踪
Usage Examples | 使用示例:
// Create analyzer
AccessPatternAnalyzer<String> analyzer = AccessPatternAnalyzer.<String>builder()
.hotKeyThreshold(100) // 100 accesses = hot
.coldDataAge(Duration.ofHours(1)) // 1 hour = cold
.topKSize(10) // Track top 10
.build();
// Record accesses
analyzer.recordAccess("user:1001");
analyzer.recordAccess("user:1002");
// Get hot keys
Set<String> hotKeys = analyzer.getHotKeys();
// Get cold keys
Set<String> coldKeys = analyzer.getColdKeys();
// Get analysis report
AccessPatternReport report = analyzer.analyze();
- Since:
- JDK 25, opencode-base-cache V2.0.5
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordAccess pattern analysis report 访问模式分析报告static classBuilder for AccessPatternAnalyzer AccessPatternAnalyzer 构建器static final recordKey with access count 带访问计数的键 -
Method Summary
Modifier and TypeMethodDescriptionanalyze()Generate full analysis report 生成完整分析报告static <K> AccessPatternAnalyzer.Builder<K> builder()Create a builder 创建构建器voidclear()Clear all tracking data 清除所有跟踪数据static <K> AccessPatternAnalyzer<K> create()Create with default settings 使用默认设置创建longgetAccessCount(K key) Get access count for a specific key 获取特定键的访问计数getBottomK(int k) Get bottom K least accessed keys 获取访问最少的 Bottom K 键Get cold keys (not accessed recently) 获取冷数据键(最近未访问)Get hot keys (frequently accessed) 获取热点键(频繁访问)getLastAccess(K key) Get last access time for a key 获取键的最后访问时间longgetMissCount(K key) Get miss count for a specific key 获取特定键的未命中计数getTopK()Get top K most accessed keys 获取访问最多的 Top K 键getTopK(int k) Get top K most accessed keys 获取访问最多的 Top K 键intPrune cold entries older than specified age 修剪超过指定年龄的冷条目voidrecordAccess(K key) Record an access to a key 记录键的访问voidrecordAccess(K key, long count) Record multiple accesses to a key 记录键的多次访问voidrecordMiss(K key) Record a miss (access but not found) 记录未命中(访问但未找到)voidRemove tracking for a key 移除键的跟踪intsize()Get tracked key count 获取跟踪的键数量
-
Method Details
-
builder
Create a builder 创建构建器- Type Parameters:
K- key type | 键类型- Returns:
- builder | 构建器
-
create
Create with default settings 使用默认设置创建- Type Parameters:
K- key type | 键类型- Returns:
- analyzer | 分析器
-
recordAccess
-
recordAccess
Record multiple accesses to a key 记录键的多次访问- Parameters:
key- the key | 键count- access count | 访问次数
-
recordMiss
Record a miss (access but not found) 记录未命中(访问但未找到)- Parameters:
key- the key | 键
-
getHotKeys
-
getColdKeys
-
getTopK
Get top K most accessed keys 获取访问最多的 Top K 键- Returns:
- list of top K keys with counts | Top K 键及其计数列表
-
getTopK
Get top K most accessed keys 获取访问最多的 Top K 键- Parameters:
k- number of keys to return | 要返回的键数量- Returns:
- list of top K keys with counts | Top K 键及其计数列表
-
getBottomK
Get bottom K least accessed keys 获取访问最少的 Bottom K 键- Parameters:
k- number of keys to return | 要返回的键数量- Returns:
- list of bottom K keys with counts | Bottom K 键及其计数列表
-
getAccessCount
Get access count for a specific key 获取特定键的访问计数- Parameters:
key- the key | 键- Returns:
- access count | 访问计数
-
getMissCount
Get miss count for a specific key 获取特定键的未命中计数- Parameters:
key- the key | 键- Returns:
- miss count | 未命中计数
-
getLastAccess
-
analyze
Generate full analysis report 生成完整分析报告- Returns:
- analysis report | 分析报告
-
remove
-
clear
public void clear()Clear all tracking data 清除所有跟踪数据 -
pruneCold
Prune cold entries older than specified age 修剪超过指定年龄的冷条目- Parameters:
age- maximum age | 最大年龄- Returns:
- number of entries pruned | 修剪的条目数
-
size
public int size()Get tracked key count 获取跟踪的键数量- Returns:
- key count | 键数量
-