From ecdc1e8639ca930a5fb23732b500894f54914428 Mon Sep 17 00:00:00 2001 From: nea Date: Wed, 8 Feb 2023 23:26:34 +0100 Subject: Lower cache for /pv to 30 seconds and rename cacheDuration to max age --- .../moulberry/notenoughupdates/profileviewer/ProfileViewer.java | 2 ++ .../java/io/github/moulberry/notenoughupdates/util/ApiUtil.java | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java index 17a14d1f..6f8427ae 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java @@ -42,6 +42,7 @@ import net.minecraft.util.EnumChatFormatting; import javax.annotation.Nullable; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Base64; @@ -537,6 +538,7 @@ public class ProfileViewer { manager.apiUtils .newHypixelApiRequest("player") .queryArgument("name", nameF) + .maxCacheAge(Duration.ofSeconds(30)) .requestJson() .thenAccept(jsonObject -> { if ( diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java index 9ace59fc..708f4677 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java @@ -117,7 +117,7 @@ public class ApiUtil { private final List queryArguments = new ArrayList<>(); private String baseUrl = null; private boolean shouldGunzip = false; - private Duration cacheTimeout = Duration.ofSeconds(500); + private Duration maxCacheAge = Duration.ofSeconds(500); private String method = "GET"; private String postData = null; private String postContentType = null; @@ -131,8 +131,8 @@ public class ApiUtil { * Specify a cache timeout of {@code null} to signify an uncacheable request. * Non {@code GET} requests are always uncacheable. */ - public Request cacheTimeout(Duration cacheTimeout) { - this.cacheTimeout = cacheTimeout; + public Request maxCacheAge(Duration maxCacheAge) { + this.maxCacheAge = maxCacheAge; return this; } @@ -244,7 +244,7 @@ public class ApiUtil { } public CompletableFuture requestString() { - return ApiCache.INSTANCE.cacheRequest(this, getCacheKey(), this::requestString0, cacheTimeout); + return ApiCache.INSTANCE.cacheRequest(this, getCacheKey(), this::requestString0, maxCacheAge); } public CompletableFuture requestJson() { -- cgit