CacheUtil.newTimedCache增加有schedulePruneDelay参数的重载方法

This commit is contained in:
Looly 2024-04-18 16:34:48 +08:00
parent ab5a00cd86
commit 4240bc6523
2 changed files with 18 additions and 1 deletions

View File

@ -102,6 +102,21 @@ public class CacheUtil {
return new LRUCache<>(capacity);
}
/**
* 创建定时缓存通过定时任务自动清除过期缓存对象
*
* @param <K> Key类型
* @param <V> Value类型
* @param timeout 过期时长单位毫秒
* @param schedulePruneDelay 间隔时长单位毫秒
* @return {@link TimedCache}
* @since 5.8.28
*/
public static <K, V> TimedCache<K, V> newTimedCache(final long timeout, final long schedulePruneDelay) {
final TimedCache<K, V> cache = newTimedCache(timeout);
return cache.schedulePrune(schedulePruneDelay);
}
/**
* 创建定时缓存.
*

View File

@ -83,9 +83,11 @@ public class TimedCache<K, V> extends StampedCache<K, V> {
* 定时清理
*
* @param delay 间隔时长单位毫秒
* @return this
*/
public void schedulePrune(final long delay) {
public TimedCache<K, V> schedulePrune(final long delay) {
this.pruneJobFuture = GlobalPruneTimer.INSTANCE.schedule(this::prune, delay);
return this;
}
/**