From 059f28fbb3a90748968401317f81255b2805b0fd Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 28 Jul 2022 08:46:31 +0200 Subject: [PATCH] Add api to enable caching for TypeMapper --- src/de/steamwar/command/TabCompletionCache.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/command/TabCompletionCache.java b/src/de/steamwar/command/TabCompletionCache.java index 5cf555c..6f2d0ff 100644 --- a/src/de/steamwar/command/TabCompletionCache.java +++ b/src/de/steamwar/command/TabCompletionCache.java @@ -24,6 +24,7 @@ import lombok.EqualsAndHashCode; import lombok.experimental.UtilityClass; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.function.Supplier; @UtilityClass @@ -36,12 +37,16 @@ public class TabCompletionCache { void add(AbstractTypeMapper typeMapper, AbstractSWCommand.Cached cached) { if (cached != null) { - TabCompletionCache.cached.add(typeMapper); - if (cached.global()) TabCompletionCache.global.add(typeMapper); - TabCompletionCache.cacheDuration.put(typeMapper, cached.timeUnit().toMillis(cached.cacheDuration())); + add(typeMapper, cached.global(), cached.cacheDuration(), cached.timeUnit()); } } + public void add(AbstractTypeMapper typeMapper, boolean global, long cacheDuration, TimeUnit timeUnit) { + TabCompletionCache.cached.add(typeMapper); + if (global) TabCompletionCache.global.add(typeMapper); + TabCompletionCache.cacheDuration.put(typeMapper, timeUnit.toMillis(cacheDuration)); + } + @EqualsAndHashCode @AllArgsConstructor private static class Key {