Make cache duration configurable via Config

- Add `CACHE_TIME_MINUTES` to `Config` with a default value of 5 minutes.
- Replace hardcoded cache duration in `AuthService` with the configurable value from `Config`.
This commit is contained in:
akastijn 2025-08-02 22:32:38 +02:00
parent f42777c62a
commit 2e812ed588
2 changed files with 7 additions and 1 deletions

View File

@ -224,4 +224,9 @@ public final class Config {
private static void download_dir() {
DOWNLOAD_DIR = getString("download-dir", DOWNLOAD_DIR);
}
public static long CACHE_TIME_MINUTES = 5;
private static void cache_time_minutes() {
CACHE_TIME_MINUTES = getLong("cache-time-minutes", CACHE_TIME_MINUTES);
}
}

View File

@ -50,7 +50,8 @@ public class AuthService {
log.info("received response");
if (response.statusCode() == 200) {
String body = response.body();
cache.put(uuid, new CacheEntry(body, Instant.now().plusSeconds(TimeUnit.MINUTES.toSeconds(10))));
cache.put(uuid, new CacheEntry(body,
Instant.now().plusSeconds(TimeUnit.MINUTES.toSeconds(Config.CACHE_TIME_MINUTES))));
client.close();
return Optional.ofNullable(body);
} else {