kbendick commented on a change in pull request #3801:
URL: https://github.com/apache/iceberg/pull/3801#discussion_r774846264



##########
File path: core/src/main/java/org/apache/iceberg/CachingCatalog.java
##########
@@ -105,14 +103,14 @@ public void delete(TableIdentifier tableIdentifier, Table 
table, RemovalCause ca
   }
 
   private Cache<TableIdentifier, Table> createTableCache(Ticker ticker) {
+    boolean hasExpiration = expirationIntervalMillis > 0;
     Caffeine<TableIdentifier, Table> cacheBuilder = Caffeine
         .newBuilder()
         .softValues()
-        .removalListener(identLoggingRemovalListener);
+        .removalListener(hasExpiration ? new 
MetadataTableInvalidatingRemovalListener() : identLoggingRemovalListener);

Review comment:
       Nit: all of the stuff that gets added due to expiration should ideally 
be inside of the `if (hasExpiration)` block and things that are applied only 
when expiration isn't enabled should ideally be on the return statement just 
after that block.
   
   Can you move some of this around? Also, there's no reason to have a 
`removalListener` if cache-expiration isn't enabled. So we can remove the 
existing `identLoggingRemovalLIstener` entirely.
   
   Like this would be great as it involves fewer changes for people who 
cherry-pick.
   
   ```java
     private Cache<TableIdentifier, Table> createTableCache(Ticker ticker) {
       Caffeine<TableIdentifier, Table> cacheBuilder = Caffeine
           .newBuilder()
           .softValues();
   
       if (expirationIntervalMillis > 0) {
         return cacheBuilder
             .removalListener(new MetadataTableInvalidatingRemovalListener())
             .expireAfterAccess(Duration.ofMillis(expirationIntervalMillis))
             .ticker(ticker)
             .build();
       }
   
       return cacheBuilder.build();
     }
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to