Skip to content

Commit fb0756f

Browse files
authored
Merge branch 'apache:main' into s3compatible
2 parents 6801079 + 664f230 commit fb0756f

File tree

1 file changed

+11
-34
lines changed

1 file changed

+11
-34
lines changed

polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCache.java

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import com.github.benmanes.caffeine.cache.Expiry;
2323
import com.github.benmanes.caffeine.cache.LoadingCache;
2424
import jakarta.annotation.Nonnull;
25+
import java.time.Duration;
2526
import java.util.Map;
2627
import java.util.Optional;
2728
import java.util.Set;
28-
import java.util.concurrent.TimeUnit;
2929
import java.util.function.Function;
3030
import org.apache.iceberg.exceptions.UnprocessableEntityException;
3131
import org.apache.polaris.core.PolarisCallContext;
@@ -53,39 +53,16 @@ public StorageCredentialCache() {
5353
Caffeine.newBuilder()
5454
.maximumSize(CACHE_MAX_NUMBER_OF_ENTRIES)
5555
.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+
}))
8966
.build(
9067
key -> {
9168
// the load happen at getOrGenerateSubScopeCreds()

0 commit comments

Comments
 (0)