Skip to content

Commit

Permalink
Fix: Update storage credential cache expiration on value replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
Sreesh Maheshwar committed Mar 10, 2025
1 parent 0ab9978 commit 7429b3a
Showing 1 changed file with 11 additions and 34 deletions.
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.writing(
(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

0 comments on commit 7429b3a

Please sign in to comment.