Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use route target path as proxy cache key #788

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down
23 changes: 9 additions & 14 deletions src/main/groovy/io/seqera/wave/core/RegistryProxyService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class RegistryProxyService {
return false
}

@Deprecated
static protected String requestKey(RoutePath route, Map<String,List<String>> headers) {
assert route!=null, "Argument route cannot be null"
final hasher = Hashing.sipHash24().newHasher()
Expand Down Expand Up @@ -227,22 +228,16 @@ class RegistryProxyService {
}

DelegateResponse handleRequest(RoutePath route, Map<String,List<String>> 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<DelegateResponse, Duration>(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<DelegateResponse, Duration>(resp, ttl)
})
}

@TraceElapsedTime(thresholdMillis = '${wave.trace.proxy-service.threshold:1000}')
Expand Down
Loading