diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java index 9fa5934a887f5..4d1bd3b0c1c38 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java @@ -2342,7 +2342,7 @@ private record VersionedApiKeyDoc(ApiKeyDoc doc, String id, long seqNo, long pri private RemovalListener> getAuthCacheRemovalListener(int maximumWeight) { return notification -> { - if (RemovalReason.EVICTED == notification.getRemovalReason() && getApiKeyAuthCache().count() >= maximumWeight) { + if (RemovalReason.EVICTED == notification.getRemovalReason() && getApiKeyAuthCache().weight() >= maximumWeight) { evictionCounter.increment(); logger.trace( "API key with ID [{}] was evicted from the authentication cache, " + "possibly due to cache size limit",