Skip to content

Commit e66b409

Browse files
committed
Merge branch 'main' into felipecsl--cloud-eppo
2 parents 646d3ed + 452cddf commit e66b409

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ dependencies {
3838
implementation 'org.slf4j:slf4j-api:2.0.13'
3939
// Logback classic 1.3.x is compatible with java 8
4040
implementation 'ch.qos.logback:logback-classic:1.3.14'
41+
implementation 'org.jetbrains:annotations:13.0'
4142

42-
testImplementation 'cloud.eppo:sdk-common-jvm:3.5.0-SNAPSHOT:tests'
43+
testImplementation 'cloud.eppo:sdk-common-jvm:3.5.0:tests'
4344
testImplementation platform('org.junit:junit-bom:5.10.2')
4445
testImplementation 'org.junit.jupiter:junit-jupiter'
4546
testImplementation 'com.github.tomakehurst:wiremock-jre8:2.35.2'

src/main/java/cloud/eppo/EppoClient.java

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package cloud.eppo;
22

3+
import cloud.eppo.api.IAssignmentCache;
34
import cloud.eppo.logging.AssignmentLogger;
45
import cloud.eppo.logging.BanditLogger;
56
import java.util.Timer;
7+
import java.util.concurrent.TimeUnit;
8+
import org.jetbrains.annotations.Nullable;
69
import org.slf4j.Logger;
710
import org.slf4j.LoggerFactory;
811

@@ -36,9 +39,11 @@ private EppoClient(
3639
String host,
3740
String sdkName,
3841
String sdkVersion,
39-
AssignmentLogger assignmentLogger,
40-
BanditLogger banditLogger,
41-
boolean isGracefulModel) {
42+
@Nullable AssignmentLogger assignmentLogger,
43+
@Nullable BanditLogger banditLogger,
44+
boolean isGracefulMode,
45+
@Nullable IAssignmentCache assignmentCache,
46+
@Nullable IAssignmentCache banditAssignmentCache) {
4247
super(
4348
apiKey,
4449
host,
@@ -47,13 +52,13 @@ private EppoClient(
4752
assignmentLogger,
4853
banditLogger,
4954
null,
50-
isGracefulModel,
55+
isGracefulMode,
5156
false,
5257
true,
5358
null,
54-
null, // TODO assignmentCache,
55-
null // TODO banditCache
56-
);
59+
assignmentCache,
60+
banditAssignmentCache
61+
);
5762
}
5863

5964
/** Stops the client from polling Eppo for updated flag and bandit configurations */
@@ -73,6 +78,12 @@ public static class Builder {
7378
private long pollingIntervalMs = DEFAULT_POLLING_INTERVAL_MS;
7479
private String host = DEFAULT_HOST;
7580

81+
// Assignment and bandit caching on by default. To disable, call
82+
// `builder.assignmentCache(null).banditAssignmentCache(null);`
83+
private IAssignmentCache assignmentCache = new LRUInMemoryAssignmentCache(100);
84+
private IAssignmentCache banditAssignmentCache =
85+
new ExpiringInMemoryAssignmentCache(10, TimeUnit.MINUTES);
86+
7687
/** Sets the API Key--created within the eppo application--to use. This is required. */
7788
public Builder apiKey(String apiKey) {
7889
this.apiKey = apiKey;
@@ -135,6 +146,16 @@ public Builder host(String host) {
135146
return this;
136147
}
137148

149+
public Builder assignmentCache(IAssignmentCache assignmentCache) {
150+
this.assignmentCache = assignmentCache;
151+
return this;
152+
}
153+
154+
public Builder banditAssignmentCache(IAssignmentCache banditAssignmentCache) {
155+
this.banditAssignmentCache = banditAssignmentCache;
156+
return this;
157+
}
158+
138159
public EppoClient buildAndInit() {
139160
AppDetails appDetails = AppDetails.getInstance();
140161
String sdkName = appDetails.getName();
@@ -153,7 +174,15 @@ public EppoClient buildAndInit() {
153174

154175
instance =
155176
new EppoClient(
156-
apiKey, sdkName, sdkVersion, host, assignmentLogger, banditLogger, isGracefulMode);
177+
apiKey,
178+
sdkName,
179+
sdkVersion,
180+
host,
181+
assignmentLogger,
182+
banditLogger,
183+
isGracefulMode,
184+
assignmentCache,
185+
banditAssignmentCache);
157186

158187
// Stop any active polling
159188
stopPolling();

0 commit comments

Comments
 (0)