Skip to content

Commit

Permalink
feat: cache latest version endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniDigger committed Dec 19, 2024
1 parent f8f7668 commit 2ffbab9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions backend/src/main/java/io/papermc/hangar/config/CacheConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -192,10 +193,12 @@ public Map<String, VersionStats> 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());
Expand Down

0 comments on commit 2ffbab9

Please sign in to comment.