diff --git a/build.gradle b/build.gradle index ce84dbd..4cb5760 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ java { } group = 'cloud.eppo' -version = '3.1.1-SNAPSHOT' +version = '3.2.0-SNAPSHOT' ext.isReleaseVersion = !version.endsWith("SNAPSHOT") import org.apache.tools.ant.filters.ReplaceTokens @@ -31,7 +31,7 @@ repositories { dependencies { // Re-export classes and interfaces that will be used upstream - api 'cloud.eppo:sdk-common-jvm:3.3.1' + api 'cloud.eppo:sdk-common-jvm:3.5.0' implementation 'com.github.zafarkhaja:java-semver:0.10.2' implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.1' @@ -39,8 +39,9 @@ dependencies { implementation 'org.slf4j:slf4j-api:2.0.13' // Logback classic 1.3.x is compatible with java 8 implementation 'ch.qos.logback:logback-classic:1.3.14' + implementation 'org.jetbrains:annotations:13.0' - testImplementation 'cloud.eppo:sdk-common-jvm:3.2.0-SNAPSHOT:tests' + testImplementation 'cloud.eppo:sdk-common-jvm:3.5.0:tests' testImplementation platform('org.junit:junit-bom:5.10.2') testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'com.github.tomakehurst:wiremock-jre8:2.35.2' diff --git a/src/main/java/com/eppo/sdk/EppoClient.java b/src/main/java/com/eppo/sdk/EppoClient.java index 88aad6c..1dc2862 100644 --- a/src/main/java/com/eppo/sdk/EppoClient.java +++ b/src/main/java/com/eppo/sdk/EppoClient.java @@ -1,11 +1,16 @@ package com.eppo.sdk; import cloud.eppo.BaseEppoClient; +import cloud.eppo.api.IAssignmentCache; +import cloud.eppo.cache.ExpiringInMemoryAssignmentCache; +import cloud.eppo.cache.LRUInMemoryAssignmentCache; import cloud.eppo.logging.AssignmentLogger; import cloud.eppo.logging.BanditLogger; import com.eppo.sdk.helpers.AppDetails; import com.eppo.sdk.helpers.FetchConfigurationsTask; import java.util.Timer; +import java.util.concurrent.TimeUnit; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,9 +44,11 @@ private EppoClient( String host, String sdkName, String sdkVersion, - AssignmentLogger assignmentLogger, - BanditLogger banditLogger, - boolean isGracefulModel) { + @Nullable AssignmentLogger assignmentLogger, + @Nullable BanditLogger banditLogger, + boolean isGracefulMode, + @Nullable IAssignmentCache assignmentCache, + @Nullable IAssignmentCache banditAssignmentCache) { super( apiKey, host, @@ -50,10 +57,12 @@ private EppoClient( assignmentLogger, banditLogger, null, - isGracefulModel, + isGracefulMode, false, true, - null); + null, + assignmentCache, + banditAssignmentCache); } /** Stops the client from polling Eppo for updated flag and bandit configurations */ @@ -73,6 +82,12 @@ public static class Builder { private long pollingIntervalMs = DEFAULT_POLLING_INTERVAL_MS; private String host = DEFAULT_HOST; + // Assignment and bandit caching on by default. To disable, call + // `builder.assignmentCache(null).banditAssignmentCache(null);` + private IAssignmentCache assignmentCache = new LRUInMemoryAssignmentCache(100); + private IAssignmentCache banditAssignmentCache = + new ExpiringInMemoryAssignmentCache(10, TimeUnit.MINUTES); + /** Sets the API Key--created within the eppo application--to use. This is required. */ public Builder apiKey(String apiKey) { this.apiKey = apiKey; @@ -135,6 +150,16 @@ public Builder host(String host) { return this; } + public Builder assignmentCache(IAssignmentCache assignmentCache) { + this.assignmentCache = assignmentCache; + return this; + } + + public Builder banditAssignmentCache(IAssignmentCache banditAssignmentCache) { + this.banditAssignmentCache = banditAssignmentCache; + return this; + } + public EppoClient buildAndInit() { AppDetails appDetails = AppDetails.getInstance(); String sdkName = appDetails.getName(); @@ -153,7 +178,15 @@ public EppoClient buildAndInit() { instance = new EppoClient( - apiKey, sdkName, sdkVersion, host, assignmentLogger, banditLogger, isGracefulMode); + apiKey, + sdkName, + sdkVersion, + host, + assignmentLogger, + banditLogger, + isGracefulMode, + assignmentCache, + banditAssignmentCache); // Stop any active polling stopPolling();