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:
parent
f42777c62a
commit
2e812ed588
|
|
@ -224,4 +224,9 @@ public final class Config {
|
||||||
private static void download_dir() {
|
private static void download_dir() {
|
||||||
DOWNLOAD_DIR = getString("download-dir", 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,8 @@ public class AuthService {
|
||||||
log.info("received response");
|
log.info("received response");
|
||||||
if (response.statusCode() == 200) {
|
if (response.statusCode() == 200) {
|
||||||
String body = response.body();
|
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();
|
client.close();
|
||||||
return Optional.ofNullable(body);
|
return Optional.ofNullable(body);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user