1
1
package cloud .eppo ;
2
2
3
+ import cloud .eppo .api .IAssignmentCache ;
3
4
import cloud .eppo .logging .AssignmentLogger ;
4
5
import cloud .eppo .logging .BanditLogger ;
5
6
import java .util .Timer ;
7
+ import java .util .concurrent .TimeUnit ;
8
+ import org .jetbrains .annotations .Nullable ;
6
9
import org .slf4j .Logger ;
7
10
import org .slf4j .LoggerFactory ;
8
11
@@ -36,9 +39,11 @@ private EppoClient(
36
39
String host ,
37
40
String sdkName ,
38
41
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 ) {
42
47
super (
43
48
apiKey ,
44
49
host ,
@@ -47,13 +52,13 @@ private EppoClient(
47
52
assignmentLogger ,
48
53
banditLogger ,
49
54
null ,
50
- isGracefulModel ,
55
+ isGracefulMode ,
51
56
false ,
52
57
true ,
53
58
null ,
54
- null , // TODO assignmentCache,
55
- null // TODO banditCache
56
- );
59
+ assignmentCache ,
60
+ banditAssignmentCache
61
+ );
57
62
}
58
63
59
64
/** Stops the client from polling Eppo for updated flag and bandit configurations */
@@ -73,6 +78,12 @@ public static class Builder {
73
78
private long pollingIntervalMs = DEFAULT_POLLING_INTERVAL_MS ;
74
79
private String host = DEFAULT_HOST ;
75
80
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
+
76
87
/** Sets the API Key--created within the eppo application--to use. This is required. */
77
88
public Builder apiKey (String apiKey ) {
78
89
this .apiKey = apiKey ;
@@ -135,6 +146,16 @@ public Builder host(String host) {
135
146
return this ;
136
147
}
137
148
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
+
138
159
public EppoClient buildAndInit () {
139
160
AppDetails appDetails = AppDetails .getInstance ();
140
161
String sdkName = appDetails .getName ();
@@ -153,7 +174,15 @@ public EppoClient buildAndInit() {
153
174
154
175
instance =
155
176
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 );
157
186
158
187
// Stop any active polling
159
188
stopPolling ();
0 commit comments