Skip to content

Commit b222abe

Browse files
joshbaskarankjellp
authored andcommitted
feat: make JWK cache size and expiration configurable via properties
1 parent 5d1cbe9 commit b222abe

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

services/localega-tsd-proxy/src/main/java/no/elixir/fega/ltp/config/JwtDecoderConfig.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,30 @@
1313
@Configuration
1414
public class JwtDecoderConfig {
1515

16+
private final int maxCacheSize;
17+
private final long timeToLive;
18+
private final TimeUnit timeUnit;
19+
private final String aaiBase;
20+
21+
public JwtDecoderConfig(
22+
@Value("${jwk-cache.max-size}") int maxCacheSize,
23+
@Value("${jwk-cache.duration}") long timeToLive,
24+
@Value("${jwk-cache.time-unit}") TimeUnit timeUnit,
25+
@Value("${aai.service-base-url}") String aaiBase) {
26+
this.maxCacheSize = maxCacheSize;
27+
this.timeToLive = timeToLive;
28+
this.timeUnit = timeUnit;
29+
this.aaiBase = aaiBase;
30+
}
31+
1632
@Bean
17-
public JwtDecoder jwtDecoder(@Value("${aai.service-base-url}") String aaiBase) {
33+
public JwtDecoder jwtDecoder() {
1834

1935
com.github.benmanes.caffeine.cache.Cache<Object, Object> nativeCache =
20-
Caffeine.newBuilder().expireAfterWrite(60, TimeUnit.MINUTES).maximumSize(100).build();
36+
Caffeine.newBuilder()
37+
.expireAfterWrite(timeToLive, timeUnit)
38+
.maximumSize(maxCacheSize)
39+
.build();
2140

2241
Cache jwkCache = new CaffeineCache("jwkCache", nativeCache);
2342

services/localega-tsd-proxy/src/main/resources/application.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,8 @@ logging:
111111
org.springframework.web.servlet.DispatcherServlet: ${APP_LOG_LEVEL:INFO}
112112
com.fasterxml.jackson: ${APP_LOG_LEVEL:INFO}
113113
root: ${APP_LOG_LEVEL:INFO}
114+
115+
jwk-cache:
116+
duration: 60
117+
time-unit: minutes
118+
max-size: 100

0 commit comments

Comments
 (0)