mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-29 01:47:07 +08:00
CacheUtil.newTimedCache增加有schedulePruneDelay参数的重载方法
This commit is contained in:
parent
ab5a00cd86
commit
4240bc6523
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建定时缓存.
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user