From 5d5fd91352744febfc010708e326467d24bef798 Mon Sep 17 00:00:00 2001 From: Paolo Di Tommaso Date: Wed, 22 Jan 2025 12:55:13 +0100 Subject: [PATCH] Use route target path as proxy cache key Signed-off-by: Paolo Di Tommaso --- .../configuration/ProxyCacheConfig.groovy | 2 +- .../wave/core/RegistryProxyService.groovy | 23 ++++++++----------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/main/groovy/io/seqera/wave/configuration/ProxyCacheConfig.groovy b/src/main/groovy/io/seqera/wave/configuration/ProxyCacheConfig.groovy index 0d5021f8b..9d27aaf0f 100644 --- a/src/main/groovy/io/seqera/wave/configuration/ProxyCacheConfig.groovy +++ b/src/main/groovy/io/seqera/wave/configuration/ProxyCacheConfig.groovy @@ -35,7 +35,7 @@ import jakarta.inject.Singleton @ToString(includeNames = true, includePackage = false) class ProxyCacheConfig { - @Value('${wave.proxy-cache.duration:4m}') + @Value('${wave.proxy-cache.duration:120s}') private Duration duration @Value('${wave.proxy-cache.max-size:10000}') diff --git a/src/main/groovy/io/seqera/wave/core/RegistryProxyService.groovy b/src/main/groovy/io/seqera/wave/core/RegistryProxyService.groovy index 5be392f85..c143da70c 100644 --- a/src/main/groovy/io/seqera/wave/core/RegistryProxyService.groovy +++ b/src/main/groovy/io/seqera/wave/core/RegistryProxyService.groovy @@ -192,6 +192,7 @@ class RegistryProxyService { return false } + @Deprecated static protected String requestKey(RoutePath route, Map> headers) { assert route!=null, "Argument route cannot be null" final hasher = Hashing.sipHash24().newHasher() @@ -227,22 +228,16 @@ class RegistryProxyService { } DelegateResponse handleRequest(RoutePath route, Map> headers) { - if( !cache.enabled ) { + if( !cache.enabled || !route.isBlob() ) { return handleRequest0(route, headers) } - final key = requestKey(route, headers) - if( !key ) { - log.debug "Bypass cache for requrst route=${route}; headers=${headers}" - return handleRequest0(route, headers) - } - else { - return cache.getOrCompute(key,(String k)-> { - final resp = handleRequest0(route, headers) - // when the response is not cacheable, return null as TTL - final ttl = route.isDigest() && resp.isCacheable() ? cache.duration : null - return new Tuple2(resp, ttl) - }) - } + final key = route.getTargetPath() + return cache.getOrCompute(key,(String k)-> { + final resp = handleRequest0(route, headers) + // when the response is not cacheable, return null as TTL + final ttl = route.isDigest() && resp.isCacheable() ? cache.duration : null + return new Tuple2(resp, ttl) + }) } @TraceElapsedTime(thresholdMillis = '${wave.trace.proxy-service.threshold:1000}')