Record Class EvictionPolicy.LRU<T>
java.lang.Object
java.lang.Record
cloud.opencode.base.pool.policy.EvictionPolicy.LRU<T>
- Type Parameters:
T- the pooled object type - 池化对象类型- Record Components:
maxObjects- the maximum objects to keep - 保留的最大对象数
- All Implemented Interfaces:
EvictionPolicy<T>
- Enclosing interface:
EvictionPolicy<T>
public static record EvictionPolicy.LRU<T>(int maxObjects)
extends Record
implements EvictionPolicy<T>
Least Recently Used eviction policy.
最近最少使用驱逐策略。
Evicts objects when the idle count exceeds maxObjects.
当空闲数量超过maxObjects时驱逐对象。
- Since:
- JDK 25, opencode-base-pool V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
-
Nested Class Summary
Nested classes/interfaces inherited from interface EvictionPolicy
EvictionPolicy.Composite<T>, EvictionPolicy.IdleTime<T>, EvictionPolicy.LFU<T>, EvictionPolicy.LRU<T>, EvictionPolicy.MaxAge<T> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.booleanevict(PooledObject<T> obj, EvictionContext context) Determines if the object should be evicted.final inthashCode()Returns a hash code value for this object.intReturns the value of themaxObjectsrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
LRU
public LRU(int maxObjects) Creates an instance of aLRUrecord class.- Parameters:
maxObjects- the value for themaxObjectsrecord component
-
-
Method Details
-
evict
Description copied from interface:EvictionPolicyDetermines if the object should be evicted. 确定对象是否应被驱逐。- Specified by:
evictin interfaceEvictionPolicy<T>- Parameters:
obj- the pooled object - 池化对象context- the eviction context - 驱逐上下文- Returns:
- true if should evict - 如果应驱逐返回true
-
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. All components in this record class are compared with thecomparemethod from their corresponding wrapper classes. -
maxObjects
public int maxObjects()Returns the value of themaxObjectsrecord component.- Returns:
- the value of the
maxObjectsrecord component
-