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



##########
File path: core/src/main/java/org/apache/iceberg/CachingCatalog.java
##########
@@ -29,24 +31,86 @@
 import org.apache.iceberg.catalog.Namespace;
 import org.apache.iceberg.catalog.TableIdentifier;
 import org.apache.iceberg.exceptions.AlreadyExistsException;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
 import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class CachingCatalog implements Catalog {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(CachingCatalog.class);
+
   public static Catalog wrap(Catalog catalog) {
-    return wrap(catalog, true);
+    return wrap(catalog, false, 0);
   }
 
-  public static Catalog wrap(Catalog catalog, boolean caseSensitive) {
-    return new CachingCatalog(catalog, caseSensitive);
+  public static Catalog wrap(Catalog catalog, boolean expirationEnabled, long 
expirationIntervalMilllis) {
+    return wrap(catalog, true, expirationEnabled, expirationIntervalMilllis);
+  }
+
+  public static Catalog wrap(Catalog catalog, boolean caseSensitive, boolean 
expirationEnabled,
+      long expirationIntervalMillis) {
+    return new CachingCatalog(catalog, caseSensitive, expirationEnabled, 
expirationIntervalMillis);
   }
 
-  private final Cache<TableIdentifier, Table> tableCache = 
Caffeine.newBuilder().softValues().build();
   private final Catalog catalog;
   private final boolean caseSensitive;
+  private final boolean expirationEnabled;
+  private final long expirationIntervalMillis;
+  private Cache<TableIdentifier, Table> tableCache;
+
+  private CachingCatalog(Catalog catalog, boolean caseSensitive, boolean 
isExpirationEnabled,
+      long expirationIntervalInMillis) {
+    this.catalog = catalog;
+    this.caseSensitive = caseSensitive;
+    this.expirationEnabled = isExpirationEnabled;
+    this.expirationIntervalMillis = expirationIntervalInMillis;
 
-  private CachingCatalog(Catalog catalog, boolean caseSensitive) {
+    this.tableCache = createTableCache(expirationEnabled, 
expirationIntervalMillis);
+  }
+
+  // The tableCache should only be passed in during tests, so that a mocked 
ticker can be used
+  // to control for cache entry expiration.
+  // VisibleForTesting

Review comment:
       Oh. Thank you! I've been in the process of refactoring this, but that's 
very helpful.
   
   I'm still more comfortable with Scala's approach to package-privacy. Greatly 
appreciated!




-- 
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