Record Class CacheEntry<K,V>
java.lang.Object
java.lang.Record
cloud.opencode.base.cache.model.CacheEntry<K,V>
- Type Parameters:
K- the type of key | 键类型V- the type of value | 值类型- Record Components:
key- the cache key | 缓存键value- the cache value | 缓存值createTime- creation time in milliseconds | 创建时间(毫秒)lastAccessTime- last access time in milliseconds | 最后访问时间(毫秒)accessCount- number of times accessed | 访问次数weight- weight for capacity calculation | 容量计算权重
public record CacheEntry<K,V> (K key, V value, long createTime, long lastAccessTime, long accessCount, long weight)
extends Record
Cache Entry - Represents a single cache entry with metadata
缓存条目 - 表示带有元数据的单个缓存条目
Immutable record containing cache entry data and access statistics.
不可变记录,包含缓存条目数据和访问统计信息。
Features | 主要功能:
- Key-value storage - 键值存储
- Creation and access time tracking - 创建和访问时间跟踪
- Access count statistics - 访问次数统计
- Weight for capacity calculation - 容量计算权重
- Age and idle time calculation - 存活和空闲时间计算
Usage Examples | 使用示例:
CacheEntry<String, User> entry = new CacheEntry<>(
"user:1001", user, System.currentTimeMillis(),
System.currentTimeMillis(), 0, 1);
// Get age - 获取存活时间
long age = entry.age();
// Get idle time - 获取空闲时间
long idle = entry.idleTime();
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Null-safe: Partial (key cannot be null) - 空值安全: 部分(键不能为 null)
- Since:
- JDK 25, opencode-base-cache V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCacheEntry(K key, V value) Create entry with default weight of 1 创建默认权重为 1 的条目CacheEntry(K key, V value, long weight) Create entry with specified weight 创建指定权重的条目CacheEntry(K key, V value, long createTime, long lastAccessTime, long accessCount, long weight) Creates an instance of aCacheEntryrecord class. -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the value of theaccessCountrecord component.longage()Get age in milliseconds (time since creation) 获取存活时间(毫秒,自创建以来)longReturns the value of thecreateTimerecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.longidleTime()Get idle time in milliseconds (time since last access) 获取空闲时间(毫秒,自最后访问以来)key()Returns the value of thekeyrecord component.longReturns the value of thelastAccessTimerecord component.CacheEntry<K, V> Create new entry with updated access time and count 创建更新访问时间和次数的新条目final StringtoString()Returns a string representation of this record class.value()Returns the value of thevaluerecord component.longweight()Returns the value of theweightrecord component.CacheEntry<K, V> Create new entry with updated value 创建更新值的新条目CacheEntry<K, V> withWeight(long newWeight) Create new entry with updated weight 创建更新权重的新条目
-
Constructor Details
-
CacheEntry
-
CacheEntry
-
CacheEntry
public CacheEntry(K key, V value, long createTime, long lastAccessTime, long accessCount, long weight) Creates an instance of aCacheEntryrecord class.- Parameters:
key- the value for thekeyrecord componentvalue- the value for thevaluerecord componentcreateTime- the value for thecreateTimerecord componentlastAccessTime- the value for thelastAccessTimerecord componentaccessCount- the value for theaccessCountrecord componentweight- the value for theweightrecord component
-
-
Method Details
-
age
public long age()Get age in milliseconds (time since creation) 获取存活时间(毫秒,自创建以来)- Returns:
- age in milliseconds | 存活时间(毫秒)
-
idleTime
public long idleTime()Get idle time in milliseconds (time since last access) 获取空闲时间(毫秒,自最后访问以来)- Returns:
- idle time in milliseconds | 空闲时间(毫秒)
-
recordAccess
Create new entry with updated access time and count 创建更新访问时间和次数的新条目- Returns:
- new entry with updated access info | 更新后的新条目
-
withValue
Create new entry with updated value 创建更新值的新条目- Parameters:
newValue- the new value | 新值- Returns:
- new entry with updated value | 更新值后的新条目
-
withWeight
Create new entry with updated weight 创建更新权重的新条目- Parameters:
newWeight- the new weight | 新权重- Returns:
- new entry with updated weight | 更新权重后的新条目
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
key
-
value
-
createTime
public long createTime()Returns the value of thecreateTimerecord component.- Returns:
- the value of the
createTimerecord component
-
lastAccessTime
public long lastAccessTime()Returns the value of thelastAccessTimerecord component.- Returns:
- the value of the
lastAccessTimerecord component
-
accessCount
public long accessCount()Returns the value of theaccessCountrecord component.- Returns:
- the value of the
accessCountrecord component
-
weight
-