Skip to content

Commit 9b3971c

Browse files
committed
Assignment and Bandit caching
1 parent 16a1c0f commit 9b3971c

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ 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-SNAPSHOT'
3535

3636
implementation 'com.github.zafarkhaja:java-semver:0.10.2'
3737
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.1'

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
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;
913
import org.slf4j.Logger;
1014
import org.slf4j.LoggerFactory;
1115

@@ -41,7 +45,9 @@ private EppoClient(
4145
String sdkVersion,
4246
AssignmentLogger assignmentLogger,
4347
BanditLogger banditLogger,
44-
boolean isGracefulModel) {
48+
boolean isGracefulModel,
49+
IAssignmentCache assignmentCache,
50+
IAssignmentCache banditAssignmentCache) {
4551
super(
4652
apiKey,
4753
host,
@@ -53,7 +59,9 @@ private EppoClient(
5359
isGracefulModel,
5460
false,
5561
true,
56-
null);
62+
null,
63+
assignmentCache,
64+
banditAssignmentCache);
5765
}
5866

5967
/** Stops the client from polling Eppo for updated flag and bandit configurations */
@@ -73,6 +81,12 @@ public static class Builder {
7381
private long pollingIntervalMs = DEFAULT_POLLING_INTERVAL_MS;
7482
private String host = DEFAULT_HOST;
7583

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

152+
public Builder assignmentCache(IAssignmentCache assignmentCache) {
153+
this.assignmentCache = assignmentCache;
154+
return this;
155+
}
156+
157+
public Builder banditAssignmentCache(IAssignmentCache banditAssignmentCache) {
158+
this.banditAssignmentCache = banditAssignmentCache;
159+
return this;
160+
}
161+
138162
public EppoClient buildAndInit() {
139163
AppDetails appDetails = AppDetails.getInstance();
140164
String sdkName = appDetails.getName();
@@ -153,7 +177,15 @@ public EppoClient buildAndInit() {
153177

154178
instance =
155179
new EppoClient(
156-
apiKey, sdkName, sdkVersion, host, assignmentLogger, banditLogger, isGracefulMode);
180+
apiKey,
181+
sdkName,
182+
sdkVersion,
183+
host,
184+
assignmentLogger,
185+
banditLogger,
186+
isGracefulMode,
187+
assignmentCache,
188+
banditAssignmentCache);
157189

158190
// Stop any active polling
159191
stopPolling();

0 commit comments

Comments
 (0)