diff --git a/backend/src/main/java/io/papermc/hangar/config/CacheConfig.java b/backend/src/main/java/io/papermc/hangar/config/CacheConfig.java index 2f6374718..00b555fd3 100644 --- a/backend/src/main/java/io/papermc/hangar/config/CacheConfig.java +++ b/backend/src/main/java/io/papermc/hangar/config/CacheConfig.java @@ -42,6 +42,7 @@ public class CacheConfig { public static final String AVATARS = "avatars-cache"; public static final String USERNAME = "username-cache"; public static final String VERSION_DEPENDENCIES = "version-dependencies-cache"; + public static final String LATEST_VERSION = "latest-version-cache"; private final CacheMetricsRegistrar cacheMetricsRegistrar; private final CaffeineCacheManager cacheManager; @@ -75,7 +76,7 @@ Cache platformFullCache() { @Bean(PROJECTS) Cache projectsCache() { - return this.createCache(PROJECTS, Duration.ofHours(1), 10); + return this.createCache(PROJECTS, Duration.ofHours(1), 100); } @Bean(CATEGORIES) @@ -170,7 +171,7 @@ Cache userSitemapCache() { @Bean(AVATARS) Cache avatarsCache() { - return this.createCache(AVATARS, Duration.ofMinutes(30), 200); + return this.createCache(AVATARS, Duration.ofMinutes(30), 2000); } @Bean(USERNAME) @@ -180,7 +181,12 @@ Cache usernameCache() { @Bean(VERSION_DEPENDENCIES) Cache versionDependenciesCache() { - return this.createCache(VERSION_DEPENDENCIES, Duration.ofMinutes(30), 200); + return this.createCache(VERSION_DEPENDENCIES, Duration.ofMinutes(30), 2000); + } + + @Bean(LATEST_VERSION) + Cache latestVersionCache() { + return this.createCache(LATEST_VERSION, Duration.ofMinutes(30), 2000); } @PostConstruct diff --git a/backend/src/main/java/io/papermc/hangar/service/api/VersionsApiService.java b/backend/src/main/java/io/papermc/hangar/service/api/VersionsApiService.java index 554826d6e..4e0c36ea2 100644 --- a/backend/src/main/java/io/papermc/hangar/service/api/VersionsApiService.java +++ b/backend/src/main/java/io/papermc/hangar/service/api/VersionsApiService.java @@ -30,6 +30,7 @@ import java.util.stream.Stream; import org.checkerframework.checker.nullness.qual.Nullable; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -192,10 +193,12 @@ public Map getVersionStats(final String slug, final String return this.versionsApiDAO.getVersionStats(slug, versionString, fromDate, toDate); } + @Cacheable("latestVersion") public @Nullable String latestVersion(final String slug) { return this.latestVersion(slug, this.config.channels.nameDefault()); } + @Cacheable("latestVersion") public @Nullable String latestVersion(final String slug, final String channel) { final boolean canSeeHidden = this.getGlobalPermissions().has(Permission.SeeHidden); final String version = this.versionsApiDAO.getLatestVersion(slug, channel, canSeeHidden, this.getHangarUserId());