diff --git a/src/main/java/io/cryostat/expressions/MatchExpressionEvaluator.java b/src/main/java/io/cryostat/expressions/MatchExpressionEvaluator.java index 92f046625..f388c59b3 100644 --- a/src/main/java/io/cryostat/expressions/MatchExpressionEvaluator.java +++ b/src/main/java/io/cryostat/expressions/MatchExpressionEvaluator.java @@ -19,7 +19,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Optional; import java.util.concurrent.CompletionException; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -29,10 +28,8 @@ import io.cryostat.targets.Target.Annotations; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import io.quarkus.cache.Cache; import io.quarkus.cache.CacheManager; import io.quarkus.cache.CacheResult; -import io.quarkus.cache.CaffeineCache; import io.quarkus.cache.CompositeCacheKey; import io.quarkus.vertx.ConsumeEvent; import jakarta.annotation.Nullable; @@ -103,33 +100,19 @@ boolean load(String matchExpression, Target target) throws ScriptException { } void invalidate(String matchExpression) { - Optional cache = cacheManager.getCache(CACHE_NAME); - if (cache.isPresent()) { - var it = cache.get().as(CaffeineCache.class).keySet().iterator(); - while (it.hasNext()) { - CompositeCacheKey entry = (CompositeCacheKey) it.next(); - String matchExpressionKey = (String) entry.getKeyElements()[0]; - if (Objects.equals(matchExpression, matchExpressionKey)) { - cache.get() - .invalidate(entry) - .invoke( - () -> { - logger.debugv( - "Expression {0} invalidated in cache {1}", - matchExpression, CACHE_NAME); - }) - .subscribe() - .with( - (v) -> {}, - (e) -> { - logger.errorv( - "Error invalidating expression {0} in cache {1}:" - + " {2}", - matchExpression, CACHE_NAME, e); - }); - } - } - } + // 0-index is important here. the argument order of the load() method determines the + // composite key order + cacheManager + .getCache(CACHE_NAME) + .ifPresent( + c -> + c.invalidateIf( + k -> + Objects.equals( + (String) + ((CompositeCacheKey) k) + .getKeyElements()[0], + matchExpression))); } public boolean applies(MatchExpression matchExpression, Target target) throws ScriptException {