This is an automated email from the ASF dual-hosted git repository.

dimas pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git


The following commit(s) were added to refs/heads/main by this push:
     new 664f23003  Use Caffeine's `Expiry.creating` for 
`StorageCredentialCache` (#1142)
664f23003 is described below

commit 664f23003833f52fbbb38ebc0eb47db59e2785d8
Author: smaheshwar-pltr <[email protected]>
AuthorDate: Wed Mar 12 20:37:43 2025 +0000

     Use Caffeine's `Expiry.creating` for `StorageCredentialCache` (#1142)
    
    * Use Caffeine's `Expiry.writing` for `StorageCredentialCache`
    
    * Change to `Expire.creating`
    
    ---------
    
    Co-authored-by: Sreesh Maheshwar <[email protected]>
---
 .../core/storage/cache/StorageCredentialCache.java | 45 ++++++----------------
 1 file changed, 11 insertions(+), 34 deletions(-)

diff --git 
a/polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCache.java
 
b/polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCache.java
index a80b38aa4..10b239da3 100644
--- 
a/polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCache.java
+++ 
b/polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCache.java
@@ -22,10 +22,10 @@ import com.github.benmanes.caffeine.cache.Caffeine;
 import com.github.benmanes.caffeine.cache.Expiry;
 import com.github.benmanes.caffeine.cache.LoadingCache;
 import jakarta.annotation.Nonnull;
+import java.time.Duration;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
-import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import org.apache.iceberg.exceptions.UnprocessableEntityException;
 import org.apache.polaris.core.PolarisCallContext;
@@ -53,39 +53,16 @@ public class StorageCredentialCache {
         Caffeine.newBuilder()
             .maximumSize(CACHE_MAX_NUMBER_OF_ENTRIES)
             .expireAfter(
-                new Expiry<StorageCredentialCacheKey, 
StorageCredentialCacheEntry>() {
-                  @Override
-                  public long expireAfterCreate(
-                      StorageCredentialCacheKey key,
-                      StorageCredentialCacheEntry entry,
-                      long currentTime) {
-                    long expireAfterMillis =
-                        Math.max(
-                            0,
-                            Math.min(
-                                (entry.getExpirationTime() - 
System.currentTimeMillis()) / 2,
-                                maxCacheDurationMs()));
-                    return TimeUnit.MILLISECONDS.toNanos(expireAfterMillis);
-                  }
-
-                  @Override
-                  public long expireAfterUpdate(
-                      StorageCredentialCacheKey key,
-                      StorageCredentialCacheEntry entry,
-                      long currentTime,
-                      long currentDuration) {
-                    return currentDuration;
-                  }
-
-                  @Override
-                  public long expireAfterRead(
-                      StorageCredentialCacheKey key,
-                      StorageCredentialCacheEntry entry,
-                      long currentTime,
-                      long currentDuration) {
-                    return currentDuration;
-                  }
-                })
+                Expiry.creating(
+                    (StorageCredentialCacheKey key, 
StorageCredentialCacheEntry entry) -> {
+                      long expireAfterMillis =
+                          Math.max(
+                              0,
+                              Math.min(
+                                  (entry.getExpirationTime() - 
System.currentTimeMillis()) / 2,
+                                  maxCacheDurationMs()));
+                      return Duration.ofMillis(expireAfterMillis);
+                    }))
             .build(
                 key -> {
                   // the load happen at getOrGenerateSubScopeCreds()

Reply via email to