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



##########
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:
       A little goofy but you can make these package private with 
`@VisibileForTesting` then in the test source add a helper class in the same 
package (`org.apache.iceberg`) that has public static factory methods for them 
i.e. `CachingCatalogTestHelper.create(...)`. This way the constructors are 
removed from the public API at least and scoped to test usage.




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