diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/NetworkPage.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/NetworkPage.java index 60d870241..c939bf3be 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/NetworkPage.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/NetworkPage.java @@ -21,7 +21,7 @@ import com.djrapitops.plan.delivery.formatting.Formatters; import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer; import com.djrapitops.plan.delivery.rendering.html.Contributors; import com.djrapitops.plan.delivery.webserver.cache.DataID; -import com.djrapitops.plan.delivery.webserver.cache.JSONCache; +import com.djrapitops.plan.delivery.webserver.cache.JSONStorage; import com.djrapitops.plan.extension.implementation.results.ExtensionData; import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery; import com.djrapitops.plan.identification.ServerInfo; @@ -54,6 +54,7 @@ public class NetworkPage implements Page { private final Theme theme; private final Locale locale; private final ServerInfo serverInfo; + private final JSONStorage jsonStorage; private final Formatters formatters; NetworkPage( @@ -65,6 +66,7 @@ public class NetworkPage implements Page { Theme theme, Locale locale, ServerInfo serverInfo, + JSONStorage jsonStorage, Formatters formatters ) { this.templateHtml = templateHtml; @@ -74,6 +76,7 @@ public class NetworkPage implements Page { this.theme = theme; this.locale = locale; this.serverInfo = serverInfo; + this.jsonStorage = jsonStorage; this.formatters = formatters; } @@ -105,8 +108,17 @@ public class NetworkPage implements Page { return new ServerPluginTabs(extensionData, formatters); }); - String nav = JSONCache.getOrCacheString(DataID.EXTENSION_NAV, serverUUID, () -> pluginTabs.get().getNav()); - String tabs = JSONCache.getOrCacheString(DataID.EXTENSION_TABS, serverUUID, () -> pluginTabs.get().getTabs()); + long after = System.currentTimeMillis() - config.get(WebserverSettings.REDUCED_REFRESH_BARRIER); + String navIdentifier = DataID.EXTENSION_NAV.of(serverUUID); + String tabIdentifier = DataID.EXTENSION_TABS.of(serverUUID); + String nav = jsonStorage.fetchJsonMadeAfter(navIdentifier, after).orElseGet(() -> { + jsonStorage.invalidateOlder(navIdentifier, after); + return jsonStorage.storeJson(navIdentifier, pluginTabs.get().getNav()); + }).json; + String tabs = jsonStorage.fetchJsonMadeAfter(tabIdentifier, after).orElseGet(() -> { + jsonStorage.invalidateOlder(tabIdentifier, after); + return jsonStorage.storeJson(tabIdentifier, pluginTabs.get().getTabs()); + }).json; PlaceholderReplacer pluginPlaceholders = new PlaceholderReplacer(); pluginPlaceholders.put("networkDisplayName", config.get(ProxySettings.NETWORK_NAME)); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/PageFactory.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/PageFactory.java index f167edce8..35536600c 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/PageFactory.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/PageFactory.java @@ -21,6 +21,7 @@ import com.djrapitops.plan.delivery.formatting.Formatters; import com.djrapitops.plan.delivery.rendering.html.icon.Icon; import com.djrapitops.plan.delivery.web.ResourceService; import com.djrapitops.plan.delivery.web.resolver.exception.NotFoundException; +import com.djrapitops.plan.delivery.webserver.cache.JSONStorage; import com.djrapitops.plan.extension.implementation.results.ExtensionData; import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery; import com.djrapitops.plan.identification.Server; @@ -60,6 +61,7 @@ public class PageFactory { private final Lazy theme; private final Lazy dbSystem; private final Lazy serverInfo; + private final Lazy jsonStorage; private final Lazy formatters; private final Lazy debugLogger; private final Lazy timings; @@ -74,6 +76,7 @@ public class PageFactory { Lazy theme, Lazy dbSystem, Lazy serverInfo, + Lazy jsonStorage, Lazy formatters, Lazy debugLogger, Lazy timings, @@ -86,6 +89,7 @@ public class PageFactory { this.theme = theme; this.dbSystem = dbSystem; this.serverInfo = serverInfo; + this.jsonStorage = jsonStorage; this.formatters = formatters; this.debugLogger = debugLogger; this.timings = timings; @@ -125,6 +129,7 @@ public class PageFactory { versionChecker.get(), dbSystem.get(), serverInfo.get(), + jsonStorage.get(), formatters.get() ); } @@ -178,7 +183,9 @@ public class PageFactory { dbSystem.get(), versionChecker.get(), config.get(), theme.get(), locale.get(), - serverInfo.get(), formatters.get()); + serverInfo.get(), + jsonStorage.get(), + formatters.get()); } public Page internalErrorPage(String message, Throwable error) { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/ServerPage.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/ServerPage.java index d1071f602..f6b0c0ab1 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/ServerPage.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/ServerPage.java @@ -22,7 +22,7 @@ import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer; import com.djrapitops.plan.delivery.rendering.html.Contributors; import com.djrapitops.plan.delivery.rendering.html.Html; import com.djrapitops.plan.delivery.webserver.cache.DataID; -import com.djrapitops.plan.delivery.webserver.cache.JSONCache; +import com.djrapitops.plan.delivery.webserver.cache.JSONStorage; import com.djrapitops.plan.extension.implementation.results.ExtensionData; import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery; import com.djrapitops.plan.identification.Server; @@ -54,6 +54,7 @@ public class ServerPage implements Page { private final VersionChecker versionChecker; private final DBSystem dbSystem; private final ServerInfo serverInfo; + private final JSONStorage jsonStorage; private final Formatters formatters; ServerPage( @@ -64,6 +65,7 @@ public class ServerPage implements Page { VersionChecker versionChecker, DBSystem dbSystem, ServerInfo serverInfo, + JSONStorage jsonStorage, Formatters formatters ) { this.templateHtml = templateHtml; @@ -74,6 +76,7 @@ public class ServerPage implements Page { this.versionChecker = versionChecker; this.dbSystem = dbSystem; this.serverInfo = serverInfo; + this.jsonStorage = jsonStorage; this.formatters = formatters; } @@ -99,8 +102,17 @@ public class ServerPage implements Page { return new ServerPluginTabs(extensionData, formatters); }); - String nav = JSONCache.getOrCacheString(DataID.EXTENSION_NAV, serverUUID, () -> pluginTabs.get().getNav()); - String tabs = JSONCache.getOrCacheString(DataID.EXTENSION_TABS, serverUUID, () -> pluginTabs.get().getTabs()); + long after = System.currentTimeMillis() - config.get(WebserverSettings.REDUCED_REFRESH_BARRIER); + String navIdentifier = DataID.EXTENSION_NAV.of(serverUUID); + String tabIdentifier = DataID.EXTENSION_TABS.of(serverUUID); + String nav = jsonStorage.fetchJsonMadeAfter(navIdentifier, after).orElseGet(() -> { + jsonStorage.invalidateOlder(navIdentifier, after); + return jsonStorage.storeJson(navIdentifier, pluginTabs.get().getNav()); + }).json; + String tabs = jsonStorage.fetchJsonMadeAfter(tabIdentifier, after).orElseGet(() -> { + jsonStorage.invalidateOlder(tabIdentifier, after); + return jsonStorage.storeJson(tabIdentifier, pluginTabs.get().getTabs()); + }).json; PlaceholderReplacer pluginPlaceholders = new PlaceholderReplacer(); pluginPlaceholders.put("serverUUID", serverUUID.toString());