From 20117e764d3a4f444efd06c846449395caac20aa Mon Sep 17 00:00:00 2001
From: Aaron <51387595+AzureAaron@users.noreply.github.com>
Date: Mon, 19 Feb 2024 14:42:58 -0500
Subject: Support the local memory cache for the API (#558)
---
src/main/java/de/hysky/skyblocker/utils/Http.java | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
(limited to 'src/main/java')
diff --git a/src/main/java/de/hysky/skyblocker/utils/Http.java b/src/main/java/de/hysky/skyblocker/utils/Http.java
index 17079d15..58deced2 100644
--- a/src/main/java/de/hysky/skyblocker/utils/Http.java
+++ b/src/main/java/de/hysky/skyblocker/utils/Http.java
@@ -53,7 +53,7 @@ public class Http {
String body = new String(decodedInputStream.readAllBytes());
HttpHeaders headers = response.headers();
- return new ApiResponse(body, response.statusCode(), getCacheStatus(headers), getAge(headers));
+ return new ApiResponse(body, response.statusCode(), getCacheStatuses(headers), getAge(headers));
}
public static HttpHeaders sendHeadRequest(String url) throws IOException, InterruptedException {
@@ -115,12 +115,12 @@ public class Http {
}
/**
- * Returns the cache status of the resource
+ * Returns the cache statuses of the resource. All possible cache status values conform to Cloudflare's.
*
- * @see Cloudflare Cache Docs
+ * @see Cloudflare Cache Docs
*/
- private static String getCacheStatus(HttpHeaders headers) {
- return headers.firstValue("CF-Cache-Status").orElse("UNKNOWN");
+ private static String[] getCacheStatuses(HttpHeaders headers) {
+ return new String[] { headers.firstValue("CF-Cache-Status").orElse("UNKNOWN"), headers.firstValue("Local-Cache-Status").orElse("UNKNOWN") };
}
private static int getAge(HttpHeaders headers) {
@@ -128,7 +128,7 @@ public class Http {
}
//TODO If ever needed, we could just replace cache status with the response headers and go from there
- public record ApiResponse(String content, int statusCode, String cacheStatus, int age) implements AutoCloseable {
+ public record ApiResponse(String content, int statusCode, String[] cacheStatuses, int age) implements AutoCloseable {
public boolean ok() {
return statusCode == 200;
@@ -139,7 +139,7 @@ public class Http {
}
public boolean cached() {
- return cacheStatus.equals("HIT");
+ return cacheStatuses[0].equals("HIT") || cacheStatuses[1].equals("HIT");
}
@Override
--
cgit