@@ -252,7 +252,7 @@ public ApiKeyService(
252252 this .threadPool = threadPool ;
253253 this .cacheHasher = Hasher .resolve (CACHE_HASH_ALGO_SETTING .get (settings ));
254254 final TimeValue ttl = CACHE_TTL_SETTING .get (settings );
255- final long maximumWeight = CACHE_MAX_KEYS_SETTING .get (settings );
255+ final int maximumWeight = CACHE_MAX_KEYS_SETTING .get (settings );
256256 if (ttl .getNanos () > 0 ) {
257257 this .apiKeyAuthCache = CacheBuilder .<String , ListenableFuture <CachedApiKeyHashResult >>builder ()
258258 .setExpireAfterAccess (ttl )
@@ -2340,9 +2340,9 @@ private static VersionedApiKeyDoc convertSearchHitToVersionedApiKeyDoc(SearchHit
23402340
23412341 private record VersionedApiKeyDoc (ApiKeyDoc doc , String id , long seqNo , long primaryTerm ) {}
23422342
2343- private RemovalListener <String , ListenableFuture <CachedApiKeyHashResult >> getAuthCacheRemovalListener (long maximumWeight ) {
2343+ private RemovalListener <String , ListenableFuture <CachedApiKeyHashResult >> getAuthCacheRemovalListener (int maximumWeight ) {
23442344 return notification -> {
2345- if (RemovalReason .EVICTED == notification .getRemovalReason () && getApiKeyAuthCache ().weight () >= maximumWeight ) {
2345+ if (RemovalReason .EVICTED == notification .getRemovalReason () && getApiKeyAuthCache ().count () >= maximumWeight ) {
23462346 evictionCounter .increment ();
23472347 logger .trace (
23482348 "API key with ID [{}] was evicted from the authentication cache, " + "possibly due to cache size limit" ,
@@ -2683,7 +2683,7 @@ private static final class ApiKeyDocCache {
26832683 private final Cache <String , BytesReference > roleDescriptorsBytesCache ;
26842684 private final LockingAtomicCounter lockingAtomicCounter ;
26852685
2686- ApiKeyDocCache (TimeValue ttl , long maximumWeight ) {
2686+ ApiKeyDocCache (TimeValue ttl , int maximumWeight ) {
26872687 this .docCache = CacheBuilder .<String , ApiKeyService .CachedApiKeyDoc >builder ()
26882688 .setMaximumWeight (maximumWeight )
26892689 .setExpireAfterWrite (ttl )
@@ -2693,7 +2693,7 @@ private static final class ApiKeyDocCache {
26932693 // multiple API keys, so we cache for longer and rely on the weight to manage the cache size.
26942694 this .roleDescriptorsBytesCache = CacheBuilder .<String , BytesReference >builder ()
26952695 .setExpireAfterAccess (TimeValue .timeValueHours (1 ))
2696- .setMaximumWeight (maximumWeight < Long . MAX_VALUE / 2 ? maximumWeight * 2L : Long . MAX_VALUE )
2696+ .setMaximumWeight (maximumWeight * 2L )
26972697 .build ();
26982698 this .lockingAtomicCounter = new LockingAtomicCounter ();
26992699 }
0 commit comments