Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
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;
Expand All @@ -51,39 +51,16 @@ public 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()
Expand Down