|
@@ -7,6 +7,7 @@ import com.google.common.cache.LoadingCache;
|
|
|
|
|
|
import java.time.Duration;
|
|
|
import java.util.concurrent.Executor;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
/**
|
|
@@ -17,8 +18,11 @@ import java.util.concurrent.Executors;
|
|
|
public class CacheUtils {
|
|
|
|
|
|
public static <K, V> LoadingCache<K, V> buildAsyncReloadingCache(Duration duration, CacheLoader<K, V> loader) {
|
|
|
- Executor executor = Executors.newCachedThreadPool( // TODO 芋艿:可能要思考下,未来要不要做成可配置
|
|
|
- TtlExecutors.getDefaultDisableInheritableThreadFactory()); // TTL 保证 ThreadLocal 可以透传
|
|
|
+ // 1. 使用 TTL 包装 ExecutorService,实现 ThreadLocal 的透传
|
|
|
+ // https://github.com/YunaiV/ruoyi-vue-pro/issues/432
|
|
|
+ ExecutorService executorService = Executors.newCachedThreadPool(); // TODO 芋艿:可能要思考下,未来要不要做成可配置
|
|
|
+ Executor executor = TtlExecutors.getTtlExecutorService(executorService);
|
|
|
+ // 2. 创建 Guava LoadingCache
|
|
|
return CacheBuilder.newBuilder()
|
|
|
// 只阻塞当前数据加载线程,其他线程返回旧值
|
|
|
.refreshAfterWrite(duration)
|