Skip to content

Commit 452cddf

Browse files
authored
feat: assignment and bandit caching with latest from sdk-common-jdk (#82)
1 parent fec58a5 commit 452cddf

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ java {
1111
}
1212

1313
group = 'cloud.eppo'
14-
version = '3.1.1-SNAPSHOT'
14+
version = '3.2.0-SNAPSHOT'
1515
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
1616

1717
import org.apache.tools.ant.filters.ReplaceTokens
@@ -31,16 +31,17 @@ repositories {
3131

3232
dependencies {
3333
// Re-export classes and interfaces that will be used upstream
34-
api 'cloud.eppo:sdk-common-jvm:3.3.1'
34+
api 'cloud.eppo:sdk-common-jvm:3.5.0'
3535

3636
implementation 'com.github.zafarkhaja:java-semver:0.10.2'
3737
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.1'
3838
implementation 'org.ehcache:ehcache:3.10.8'
3939
implementation 'org.slf4j:slf4j-api:2.0.13'
4040
// Logback classic 1.3.x is compatible with java 8
4141
implementation 'ch.qos.logback:logback-classic:1.3.14'
42+
implementation 'org.jetbrains:annotations:13.0'
4243

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

src/main/java/com/eppo/sdk/EppoClient.java

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package com.eppo.sdk;
22

33
import cloud.eppo.BaseEppoClient;
4+
import cloud.eppo.api.IAssignmentCache;
5+
import cloud.eppo.cache.ExpiringInMemoryAssignmentCache;
6+
import cloud.eppo.cache.LRUInMemoryAssignmentCache;
47
import cloud.eppo.logging.AssignmentLogger;
58
import cloud.eppo.logging.BanditLogger;
69
import com.eppo.sdk.helpers.AppDetails;
710
import com.eppo.sdk.helpers.FetchConfigurationsTask;
811
import java.util.Timer;
12+
import java.util.concurrent.TimeUnit;
13+
import org.jetbrains.annotations.Nullable;
914
import org.slf4j.Logger;
1015
import org.slf4j.LoggerFactory;
1116

@@ -39,9 +44,11 @@ private EppoClient(
3944
String host,
4045
String sdkName,
4146
String sdkVersion,
42-
AssignmentLogger assignmentLogger,
43-
BanditLogger banditLogger,
44-
boolean isGracefulModel) {
47+
@Nullable AssignmentLogger assignmentLogger,
48+
@Nullable BanditLogger banditLogger,
49+
boolean isGracefulMode,
50+
@Nullable IAssignmentCache assignmentCache,
51+
@Nullable IAssignmentCache banditAssignmentCache) {
4552
super(
4653
apiKey,
4754
host,
@@ -50,10 +57,12 @@ private EppoClient(
5057
assignmentLogger,
5158
banditLogger,
5259
null,
53-
isGracefulModel,
60+
isGracefulMode,
5461
false,
5562
true,
56-
null);
63+
null,
64+
assignmentCache,
65+
banditAssignmentCache);
5766
}
5867

5968
/** Stops the client from polling Eppo for updated flag and bandit configurations */
@@ -73,6 +82,12 @@ public static class Builder {
7382
private long pollingIntervalMs = DEFAULT_POLLING_INTERVAL_MS;
7483
private String host = DEFAULT_HOST;
7584

85+
// Assignment and bandit caching on by default. To disable, call
86+
// `builder.assignmentCache(null).banditAssignmentCache(null);`
87+
private IAssignmentCache assignmentCache = new LRUInMemoryAssignmentCache(100);
88+
private IAssignmentCache banditAssignmentCache =
89+
new ExpiringInMemoryAssignmentCache(10, TimeUnit.MINUTES);
90+
7691
/** Sets the API Key--created within the eppo application--to use. This is required. */
7792
public Builder apiKey(String apiKey) {
7893
this.apiKey = apiKey;
@@ -135,6 +150,16 @@ public Builder host(String host) {
135150
return this;
136151
}
137152

153+
public Builder assignmentCache(IAssignmentCache assignmentCache) {
154+
this.assignmentCache = assignmentCache;
155+
return this;
156+
}
157+
158+
public Builder banditAssignmentCache(IAssignmentCache banditAssignmentCache) {
159+
this.banditAssignmentCache = banditAssignmentCache;
160+
return this;
161+
}
162+
138163
public EppoClient buildAndInit() {
139164
AppDetails appDetails = AppDetails.getInstance();
140165
String sdkName = appDetails.getName();
@@ -153,7 +178,15 @@ public EppoClient buildAndInit() {
153178

154179
instance =
155180
new EppoClient(
156-
apiKey, sdkName, sdkVersion, host, assignmentLogger, banditLogger, isGracefulMode);
181+
apiKey,
182+
sdkName,
183+
sdkVersion,
184+
host,
185+
assignmentLogger,
186+
banditLogger,
187+
isGracefulMode,
188+
assignmentCache,
189+
banditAssignmentCache);
157190

158191
// Stop any active polling
159192
stopPolling();

0 commit comments

Comments
 (0)