|
22 | 22 | import com.github.benmanes.caffeine.cache.Expiry; |
23 | 23 | import com.github.benmanes.caffeine.cache.LoadingCache; |
24 | 24 | import jakarta.annotation.Nonnull; |
| 25 | +import java.time.Duration; |
25 | 26 | import java.util.Map; |
26 | 27 | import java.util.Optional; |
27 | 28 | import java.util.Set; |
28 | | -import java.util.concurrent.TimeUnit; |
29 | 29 | import java.util.function.Function; |
30 | 30 | import org.apache.iceberg.exceptions.UnprocessableEntityException; |
31 | 31 | import org.apache.polaris.core.PolarisCallContext; |
@@ -53,39 +53,16 @@ public StorageCredentialCache() { |
53 | 53 | Caffeine.newBuilder() |
54 | 54 | .maximumSize(CACHE_MAX_NUMBER_OF_ENTRIES) |
55 | 55 | .expireAfter( |
56 | | - new Expiry<StorageCredentialCacheKey, StorageCredentialCacheEntry>() { |
57 | | - @Override |
58 | | - public long expireAfterCreate( |
59 | | - StorageCredentialCacheKey key, |
60 | | - StorageCredentialCacheEntry entry, |
61 | | - long currentTime) { |
62 | | - long expireAfterMillis = |
63 | | - Math.max( |
64 | | - 0, |
65 | | - Math.min( |
66 | | - (entry.getExpirationTime() - System.currentTimeMillis()) / 2, |
67 | | - maxCacheDurationMs())); |
68 | | - return TimeUnit.MILLISECONDS.toNanos(expireAfterMillis); |
69 | | - } |
70 | | - |
71 | | - @Override |
72 | | - public long expireAfterUpdate( |
73 | | - StorageCredentialCacheKey key, |
74 | | - StorageCredentialCacheEntry entry, |
75 | | - long currentTime, |
76 | | - long currentDuration) { |
77 | | - return currentDuration; |
78 | | - } |
79 | | - |
80 | | - @Override |
81 | | - public long expireAfterRead( |
82 | | - StorageCredentialCacheKey key, |
83 | | - StorageCredentialCacheEntry entry, |
84 | | - long currentTime, |
85 | | - long currentDuration) { |
86 | | - return currentDuration; |
87 | | - } |
88 | | - }) |
| 56 | + Expiry.creating( |
| 57 | + (StorageCredentialCacheKey key, StorageCredentialCacheEntry entry) -> { |
| 58 | + long expireAfterMillis = |
| 59 | + Math.max( |
| 60 | + 0, |
| 61 | + Math.min( |
| 62 | + (entry.getExpirationTime() - System.currentTimeMillis()) / 2, |
| 63 | + maxCacheDurationMs())); |
| 64 | + return Duration.ofMillis(expireAfterMillis); |
| 65 | + })) |
89 | 66 | .build( |
90 | 67 | key -> { |
91 | 68 | // the load happen at getOrGenerateSubScopeCreds() |
|
0 commit comments